I have some macros in my document, and I want to create my own HTML for there. I follow this blog entry but I can't to make it work.

I put this code before my \begin{document}:



    % I can't understand this things too much - I'm not familiar with TeX

       {\Tg<span class="one">\Tg<code>}{\Tg</b>\Tg</span>}


And compile with: htlatex mylatexfile.tex "xhtml"

And I get this error message:

    ! Use of \one doesn't match its definition.
    l.19         \one{

My problem is, for example, I have a macro like:

    \newcommand{\myfunction}[2]{The title is: #1 an the body is \textit{#2} }

and I want to translate this in some like:

    <div class="container">
       <div class="title"><!-- #1 goes here --></div>
       <div class="content"><!-- #2 goes here --></div>

How I can do that?


tex4ht works best when your macros are saved in a .sty file and tex4ht configurations for these macros are saved in file named as the .sty file, only with .4ht suffix. In your situation, you may put your macro \myfunction to mystyle.sty:

\newcommand{\myfunction}[2]{The title is: #1 an the body is \textit{#2} }

now what to put to mystyle.4ht? You need to declare configurations for inserted html tags, redefine \myfunction to insert these tags and provide default values for configurations:



\Configure{myfunction}{\HCode{<div class="container">\Hnewline
   <div class="title">}}{\HCode{</div>
   <div class="content">}}{\HCode{</div>

simplified form of \NewConfigure is used here, with number in {} brackets you declare commands \a:name, \b:name, ... We need to declare three insertions, before and after parameters and between them.

For more information see my tex4ht tutorial. You may also need to modify the provided configurations for \Configure{myfunction} because of paragraphs handling see Control the <p> tags

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.