3

I'd like to customise the processes used when calling htlatex; in particular, I'd like to be able to switch off the conversion of included images into .png files.

With the following file, say mwe.tex:

\documentclass{article}
\usepackage{graphics}
\begin{document}
Some mathematical content: $y=x$
\includegraphics{example-image-a}
\end{document}

and myconfig.cfg

\Preamble{xhtml,mathml}
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}}
\Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}}
\Configure{@HEAD}{\HCode{<link
         rel="stylesheet" type="text/css"
         href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
  .MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}
% margin note
\begin{document}
\EndPreamble

when I run

 htlatex.exe mwe "myconfig.cfg, charset=utf-8" " -cunihtf -utf8"

part of the process converts example-image-a.eps to example-image-a.png; this is as intended, but not necessary every time I call htlatex.

How can I configure my call to htlatex so that I can toggle the image conversion step?

4

Image conversion is executed by the t4ht command. It has -p option, which can suppress the image generation when the target file exists. You can options to t4ht using slightly complicated htlatex call:

htlatex.exe mwe "myconfig.cfg, charset=utf-8" " -cunihtf -utf8" " -p"

This can be simplified using make4ht. Create a build file mwe.mk4:

if mode == "draft" then
  settings.t4ht_par = "-p"
end

The mode variable can be set on the command line using -m option. The draft mode uses only one LaTeX run instead of usual three, so it greatly speeds up the compilation. The equivalent to the htlatex call is the following make4ht command:

make4ht -um draft -c myconfig mwe

This is the result:

enter image description here

Btw, the config file can be simplified as well:

\Preamble{xhtml,mathml,html5}
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
  .MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}
% margin note
\begin{document}
\EndPreamble
  • Thank you very much, this is fantastic! Is there a reference you could provide for documentation so that I could read more about the different modes? – cmhughes Nov 23 '17 at 15:45
  • @cmhughes there is only draft mode configured by default, but you can use your own modes in the build files. – michal.h21 Nov 23 '17 at 15:55
  • @cmhughes there is a short note on page 6 of make4ht manual – michal.h21 Nov 23 '17 at 15:57
  • many thanks. the htlatex works as expected, but the make4ht command still does the conversion; do I need to alert make4ht to mwe.mk4 in some way? – cmhughes Nov 23 '17 at 16:21
  • The mk4 file is loaded automatically if it has the same basename as your TeX file. If it doesn't you can use the -e option to point to it. – michal.h21 Nov 23 '17 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.