make4ht - provide multiple configuration files












1















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?










share|improve this question


















  • 1





    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.

    – gusbrs
    Feb 26 at 9:53
















1















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?










share|improve this question


















  • 1





    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.

    – gusbrs
    Feb 26 at 9:53














1












1








1








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?










share|improve this question














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?







make4ht css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 26 at 9:15









DarioMangoniDarioMangoni

508




508








  • 1





    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.

    – gusbrs
    Feb 26 at 9:53














  • 1





    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.

    – gusbrs
    Feb 26 at 9:53








1




1





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.

– gusbrs
Feb 26 at 9:53





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.

– gusbrs
Feb 26 at 9:53










2 Answers
2






active

oldest

votes


















2














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[hidelinks]{hyperref}
    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]%
    {
    defa:myMedia{#1}%
    defb:myMedia{#2}%
    }
    renewcommandmyMedia[1]{a:myMedia#1b: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}
    newcommandmyMedia[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






share|improve this answer


























  • 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.

    – gusbrs
    Feb 26 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.

    – DarioMangoni
    Feb 27 at 8:53






  • 1





    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...

    – gusbrs
    Feb 27 at 9:13











  • Oh, sure. I have a MWE if someone is interested: sample example

    – DarioMangoni
    Feb 28 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

    – DarioMangoni
    Feb 28 at 10:44



















1














I would like to add some additional information to the Dario's answer.



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}%
renewcommandmyMedia[1]{a:myMedia#1b:myMedia}
%Configure{myMedia}{ifvmodeIgnoreParfiEndPHCode{<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}
{ifvmodeIgnoreParfiEndPHCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}NoFonts}
{HCode{" type="video/mp4"></video></div>}EndNoFonts}

endinputemptyemptyemptyemptyemptyempty
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}
Configure{AddCss}{samplestyle.css}
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" />





share|improve this answer
























  • 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.)

    – gusbrs
    11 hours ago











  • One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

    – gusbrs
    11 hours ago






  • 1





    @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 :(

    – michal.h21
    10 hours ago






  • 1





    @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

    – michal.h21
    10 hours ago






  • 1





    @gusbrs thanks for your kind words. I hope to be able to continue the work soon

    – michal.h21
    7 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476724%2fmake4ht-provide-multiple-configuration-files%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














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[hidelinks]{hyperref}
    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]%
    {
    defa:myMedia{#1}%
    defb:myMedia{#2}%
    }
    renewcommandmyMedia[1]{a:myMedia#1b: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}
    newcommandmyMedia[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






share|improve this answer


























  • 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.

    – gusbrs
    Feb 26 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.

    – DarioMangoni
    Feb 27 at 8:53






  • 1





    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...

    – gusbrs
    Feb 27 at 9:13











  • Oh, sure. I have a MWE if someone is interested: sample example

    – DarioMangoni
    Feb 28 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

    – DarioMangoni
    Feb 28 at 10:44
















2














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[hidelinks]{hyperref}
    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]%
    {
    defa:myMedia{#1}%
    defb:myMedia{#2}%
    }
    renewcommandmyMedia[1]{a:myMedia#1b: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}
    newcommandmyMedia[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






share|improve this answer


























  • 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.

    – gusbrs
    Feb 26 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.

    – DarioMangoni
    Feb 27 at 8:53






  • 1





    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...

    – gusbrs
    Feb 27 at 9:13











  • Oh, sure. I have a MWE if someone is interested: sample example

    – DarioMangoni
    Feb 28 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

    – DarioMangoni
    Feb 28 at 10:44














2












2








2







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[hidelinks]{hyperref}
    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]%
    {
    defa:myMedia{#1}%
    defb:myMedia{#2}%
    }
    renewcommandmyMedia[1]{a:myMedia#1b: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}
    newcommandmyMedia[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






share|improve this answer















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[hidelinks]{hyperref}
    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]%
    {
    defa:myMedia{#1}%
    defb:myMedia{#2}%
    }
    renewcommandmyMedia[1]{a:myMedia#1b: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}
    newcommandmyMedia[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







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 28 at 11:22

























answered Feb 26 at 10:16









DarioMangoniDarioMangoni

508




508













  • 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.

    – gusbrs
    Feb 26 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.

    – DarioMangoni
    Feb 27 at 8:53






  • 1





    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...

    – gusbrs
    Feb 27 at 9:13











  • Oh, sure. I have a MWE if someone is interested: sample example

    – DarioMangoni
    Feb 28 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

    – DarioMangoni
    Feb 28 at 10:44



















  • 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.

    – gusbrs
    Feb 26 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.

    – DarioMangoni
    Feb 27 at 8:53






  • 1





    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...

    – gusbrs
    Feb 27 at 9:13











  • Oh, sure. I have a MWE if someone is interested: sample example

    – DarioMangoni
    Feb 28 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

    – DarioMangoni
    Feb 28 at 10:44

















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.

– gusbrs
Feb 26 at 10:37







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.

– gusbrs
Feb 26 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.

– DarioMangoni
Feb 27 at 8:53





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.

– DarioMangoni
Feb 27 at 8:53




1




1





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...

– gusbrs
Feb 27 at 9:13





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...

– gusbrs
Feb 27 at 9:13













Oh, sure. I have a MWE if someone is interested: sample example

– DarioMangoni
Feb 28 at 10:35







Oh, sure. I have a MWE if someone is interested: sample example

– DarioMangoni
Feb 28 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

– DarioMangoni
Feb 28 at 10:44





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

– DarioMangoni
Feb 28 at 10:44











1














I would like to add some additional information to the Dario's answer.



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}%
renewcommandmyMedia[1]{a:myMedia#1b:myMedia}
%Configure{myMedia}{ifvmodeIgnoreParfiEndPHCode{<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}
{ifvmodeIgnoreParfiEndPHCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}NoFonts}
{HCode{" type="video/mp4"></video></div>}EndNoFonts}

endinputemptyemptyemptyemptyemptyempty
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}
Configure{AddCss}{samplestyle.css}
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" />





share|improve this answer
























  • 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.)

    – gusbrs
    11 hours ago











  • One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

    – gusbrs
    11 hours ago






  • 1





    @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 :(

    – michal.h21
    10 hours ago






  • 1





    @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

    – michal.h21
    10 hours ago






  • 1





    @gusbrs thanks for your kind words. I hope to be able to continue the work soon

    – michal.h21
    7 hours ago
















1














I would like to add some additional information to the Dario's answer.



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}%
renewcommandmyMedia[1]{a:myMedia#1b:myMedia}
%Configure{myMedia}{ifvmodeIgnoreParfiEndPHCode{<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}
{ifvmodeIgnoreParfiEndPHCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}NoFonts}
{HCode{" type="video/mp4"></video></div>}EndNoFonts}

endinputemptyemptyemptyemptyemptyempty
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}
Configure{AddCss}{samplestyle.css}
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" />





share|improve this answer
























  • 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.)

    – gusbrs
    11 hours ago











  • One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

    – gusbrs
    11 hours ago






  • 1





    @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 :(

    – michal.h21
    10 hours ago






  • 1





    @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

    – michal.h21
    10 hours ago






  • 1





    @gusbrs thanks for your kind words. I hope to be able to continue the work soon

    – michal.h21
    7 hours ago














1












1








1







I would like to add some additional information to the Dario's answer.



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}%
renewcommandmyMedia[1]{a:myMedia#1b:myMedia}
%Configure{myMedia}{ifvmodeIgnoreParfiEndPHCode{<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}
{ifvmodeIgnoreParfiEndPHCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}NoFonts}
{HCode{" type="video/mp4"></video></div>}EndNoFonts}

endinputemptyemptyemptyemptyemptyempty
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}
Configure{AddCss}{samplestyle.css}
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" />





share|improve this answer













I would like to add some additional information to the Dario's answer.



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}%
renewcommandmyMedia[1]{a:myMedia#1b:myMedia}
%Configure{myMedia}{ifvmodeIgnoreParfiEndPHCode{<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}
{ifvmodeIgnoreParfiEndPHCode{<div class="video-content"><video width="640" height="480" playsinline autoplay muted loop><source src="}NoFonts}
{HCode{" type="video/mp4"></video></div>}EndNoFonts}

endinputemptyemptyemptyemptyemptyempty
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}
Configure{AddCss}{samplestyle.css}
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" />






share|improve this answer












share|improve this answer



share|improve this answer










answered 12 hours ago









michal.h21michal.h21

31.5k447104




31.5k447104













  • 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.)

    – gusbrs
    11 hours ago











  • One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

    – gusbrs
    11 hours ago






  • 1





    @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 :(

    – michal.h21
    10 hours ago






  • 1





    @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

    – michal.h21
    10 hours ago






  • 1





    @gusbrs thanks for your kind words. I hope to be able to continue the work soon

    – michal.h21
    7 hours ago



















  • 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.)

    – gusbrs
    11 hours ago











  • One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

    – gusbrs
    11 hours ago






  • 1





    @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 :(

    – michal.h21
    10 hours ago






  • 1





    @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

    – michal.h21
    10 hours ago






  • 1





    @gusbrs thanks for your kind words. I hope to be able to continue the work soon

    – michal.h21
    7 hours ago

















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.)

– gusbrs
11 hours ago





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.)

– gusbrs
11 hours ago













One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

– gusbrs
11 hours ago





One question: could tex4ht.usr and myconfig.4ht also be placed in the main document's working directory?

– gusbrs
11 hours ago




1




1





@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 :(

– michal.h21
10 hours ago





@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 :(

– michal.h21
10 hours ago




1




1





@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

– michal.h21
10 hours ago





@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

– michal.h21
10 hours ago




1




1





@gusbrs thanks for your kind words. I hope to be able to continue the work soon

– michal.h21
7 hours ago





@gusbrs thanks for your kind words. I hope to be able to continue the work soon

– michal.h21
7 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476724%2fmake4ht-provide-multiple-configuration-files%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?