# make4ht - provide multiple configuration files

In post How can I override tex4ht's CSS in a single .css file? the proposed solution requires to add a configuration file (namely sample.cfg). So, if I have sample.tex I may add sample.cfg.

However, in my case, I'm using an additional configuration file called myMedia.cfg to add some additional features to my document.

This means (if I got it right) that I should use --config myMedia to add this file to the compilation.

make4ht --utf8 --shell-escape sample.tex --config myMedia


Now, I end up with two configuration files:

• one with all the required commands for myMedia
• another one file with CSS configuration (the one with \CssFile[] \EndCssFile)

So:

• should I add something like --config myMedia,sample or --config "myMedia,sample"? well, it doesn't work... it loads only the first config file
• should I merge myMedia.cfg and sample.cfg together? It looks really ugly, but it actually works

Am I missing something? Should I change the compiler?

• I'm not really sure about this, but given the usual constructs in a tex4ht config file, such as \Preamble{...}, \begin{document}, and \EndPreamble, it will probably be difficult to have two of them (how would things be stacked/ordered then?). I haven't tested, but you might be able to use \input{myMedia} inside sample.cfg for a duly prepared myMedia.tex. Feb 26, 2019 at 9:53

Only one configuration file can be used by tex4ht, but its content can be included by the \input command, so it is possible to reuse parts of the configuration between different projects. It is possible to save the particular files in the local TEXMF directory, so they are accessible from any location on a computer.

In your case, as you created a custom package, you need to create a configuration file for that package, called packagename.4ht. You provided configuration file for your package myMedia.4ht in your answer. I would change it a bit:

\NewConfigure{myMedia}{2}%
\renewcommand\myMedia[1]{\a:myMedia#1\b:myMedia}
%\Configure{myMedia}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}\NoFonts}{\HCode{" type="video/mp4"></video></div>}\EndNoFonts}

\Hinput{myMedia}


The \NewConfigure{myMedia}{2} command creates so called hooks which can be inserted into the redefined commands and configured using the \Configure command. It does exactly the same thing as the \NewConfigure from your answer, but it is a bit simpler.

It is better to keep the \Configure commands out of the package configuration files. Why? When tex4ht process the document preamble, it loads configuration files for all used packages, in order to redefine commands and insert the hooks. After that, configuration files for the current output format are executed. tex4ht can thus support HTML, ODT and some more output formats. So configurations for HTML are provided in html4.4ht or html5.4ht files, for ODT format in ooffice.4ht etc. It is of course not possible for you to insert your custom configurations to these files, as your edits would be removed in the next tex4ht update.

If you are sure to support only HTML, you can keep the \Configure command in myMedia.4ht, even if it is not the optimal solution. Another possibility is to put it in the .cfg file and last one is to create a custom output format. I will show this possibility just for the educational purposes:

Output formats are defined in the tex4ht.4ht file. This is the definition for html5 format, for example:

\Configure{html5}{%
\:CheckOption{info}\if:Option
\Hinclude[*]{infoht4.4ht}\fi
\:CheckOption{info}\if:Option
\Hinclude[*]{infomml.4ht}\fi
\Hinclude[*]{html4.4ht}%
\Hinclude[*]{unicode.4ht}%
\:CheckOption{mathml}\if:Option%
\else\:CheckOption{mathml-}\fi%
\if:Option%
\Hinclude[*]{mathml.4ht}%
\Hinclude[*]{html-mml.4ht}%
\else
\Hinclude[*]{html4-math.4ht}%
\fi
\:CheckOption{svg}%
\if:Option \else\:CheckOption{svg-}\fi
\if:Option \else\:CheckOption{svg-obj}\fi
\if:Option \else\:CheckOption{svg-inline}\fi
\if:Option \Hinclude[*]{svg-option.4ht}%
\:CheckOption{info}\if:Option \Hinclude[*]{infosvg.4ht}\fi
\fi
\Hinclude[*]{html5.4ht}%
}


The \Configure command here declares a code that is executed when the mark used as it's argument is used as an option for tex4ht. html5 is added automatically by make4ht so this code is executed by default.

The custom output format can be defined in the tex4ht.usr file. It is possible to place it in the local TEXMF tree, for example ~/texmf/tex/latex/tex4ht/tex4ht.usr seems to work. It's contents may look like this:

\Configure{myhtml5}{%
\:CheckOption{info}\if:Option
\Hinclude[*]{infoht4.4ht}\fi
\:CheckOption{info}\if:Option
\Hinclude[*]{infomml.4ht}\fi
\Hinclude[*]{html4.4ht}%
\Hinclude[*]{unicode.4ht}%
\:CheckOption{mathml}\if:Option%
\else\:CheckOption{mathml-}\fi%
\if:Option%
\Hinclude[*]{mathml.4ht}%
\Hinclude[*]{html-mml.4ht}%
\else
\Hinclude[*]{html4-math.4ht}%
\fi
\:CheckOption{svg}%
\if:Option \else\:CheckOption{svg-}\fi
\if:Option \else\:CheckOption{svg-obj}\fi
\if:Option \else\:CheckOption{svg-inline}\fi
\if:Option \Hinclude[*]{svg-option.4ht}%
\:CheckOption{info}\if:Option \Hinclude[*]{infosvg.4ht}\fi
\fi
\Hinclude[*]{html5.4ht}%
\Hinclude[*]{myconfig.4ht}
}


The difference to the previous listing is that the mark is named myhtml5 and a new file is requested, myconfig.4ht. To request this output format, run

make4ht filename.tex "myhtml5"


The custom configurations can be then added to the myconfig.4ht file, which can be saved in the same location as tex4ht.usr:

\exit:ifnot{myMedia}
\ConfigureHinput{myMedia}

\Configure{myMedia}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}\NoFonts}
{\HCode{" type="video/mp4"></video></div>}\EndNoFonts}

\endinput\empty\empty\empty\empty\empty\empty
\endinput


I've used the template for a package from the tex4ht documentation. In general, the code for a package needs to be enclosed in \ConfigureHinput{packagename} ... \endinput. This ensures that it is executed only when the package had been used in the document. You would get warnings about missing configurations and probably unwanted HTML code in your document otherwise. The used packages are registered for the processing using the \Hinput command in the package .4ht file.

The configuration for myMedia has been modified a bit, in order to handle correctly the paragraphs. The original configuration produced invalid HTML code due to this issue. You can copy the \Configure command to the .cfg file or to the myMedia.4ht if you decide to use a simpler solutions. This is the only really necessary fix from my answer.

The last bit of information I want to provide in my answer is that it is possible to use a simpler command for inclusion of an external CSS file:

\Preamble{xhtml}
\begin{document}
\EndPreamble


It will not include the code from samplestyle.css to the main CSS file, it will just include a link to the HTML header. I think it is a preferable way in most cases.

This is the result of command

make4ht -um draft -c sample.cfg sample.tex "myhtml5"

 <hr class="figure" /><div class="figure"
>
<a id="x1-21"></a>
<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="test.mp4" type="video/mp4"></video></div>
<br /> <div class="caption"
><span class="id">Figure 1: </span><span
class="content">test</span></div><!--tex4ht:label?: x1-21 -->
</div><hr class="endfigure" />

• Hopefully, one day I'll get the hang of tex4ht & co. ;-) (+1 btw, interesting setup, I didn't know one could set a custom output type.) Mar 5, 2019 at 17:02
• One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory? Mar 5, 2019 at 17:04
• @gusbrs yes, I hope we sometimes get more collaborators. but it is hard without good documentation and my progress is pretty slow. especially since my last exhaustion :( Mar 5, 2019 at 18:34
• @gusbrs the files can be placed anywhere where they can be found by KPSE, the document directory has highest priority, so the files here should be used instead of ones in TEXMF tree Mar 5, 2019 at 18:36
• @gusbrs thanks for your kind words. I hope to be able to continue the work soon Mar 5, 2019 at 20:53

Ok, I just followed what @gusbrs suggested in the comment below (thanks a lot!) and he was right: there is no need of any myMedia.cfg. What was in there, it could just be moved into myMedia.4ht.

This solution allows to completely separate the global configuration file (sample.cfg) from other-packages files (such as myMedia.4ht).

The current working setup is the following:

• sample.tex contains the \usepackage{myMedia} command in the document preamble;

\documentclass{article}
\usepackage{graphicx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % may use latin1 instead of utf8
\usepackage{myMedia}

\begin{document}

\begin{figure}
\centering
\myMedia{test.mp4}
\caption{test}
\end{figure}

\end{document}

• sample.cfg that acts like an actual configuration file;
\Preamble{xhtml}
\begin{document}
\CssFile[samplestyle.css]
\EndCssFile
\EndPreamble

• myMedia.4ht
\NewConfigure{myMedia}[2]%
{
\def\a:myMedia{#1}%
\def\b:myMedia{#2}%
}
\renewcommand\myMedia[1]{\a:myMedia#1\b:myMedia}
\Configure{myMedia}{\HCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src=}\NoFonts}{\HCode{ type="video/mp4"></video></div>}\EndNoFonts}

• myMedia.sty
\ProvidesPackage{myMedia}
\newcommand\myMedia[1]{#1}
\endinput

• samplestyle.css contains the CSS styling for the document;
/* css.sty */
body {
text-align: justify;
}


The command line is

make4ht --utf8 --shell-escape sample.tex --config sample


For those who may need a MWE, here it is: mysample

• Glad to see it works. But, if I understand correctly now, myMedia is a package you load. If this is the case, you could simply use a file myMedia.4ht in the same folder with that content. No further intervention required. Feb 26, 2019 at 10:37
• Well, I already have such file, but not as configure file! No better explain the overall setup, I added the full list of files that I have in my folder. I don't know if there is actually another way to restructure the code to get rid of some of them. Feb 27, 2019 at 8:53
• Dario, as far as I understand, I usually take the .4ht as a container of configuration instructions associated with certain packages. The .cfg is somewhere where you can globally set (or override) things. Did you try to include what you are trying to put in myMedia.cfg alongside the rest of myMedia.4ht? Anyway, it is somewhat hard to help, as you do not provide a MWE... Feb 27, 2019 at 9:13
• Oh, sure. I have a MWE if someone is interested: sample example Feb 28, 2019 at 10:35
• Oh, yes @gusbrs! You are right! I can get rid of myMedia.cfg. I didn't know it was possible. I blindly followed the suggestion of different posts; I never tried to compact all the statements just in myMedia.4ht. I will update the answer and add a MWE for future reference. Thanks again for your suggestions Feb 28, 2019 at 10:44