Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by michal.h21 for LaTeX to HTML via Pandoc : handle a custom command

You can easily support custom commands with tex4ht. Just move declaration of the commands to standalone package, for example mycommands.sty:

\newcommand{\subchpbreak}{\fancybreak{\rotatebox[origin=c]{90}{\S}}}

and create file with same name, but .4ht extension, mycommands.4ht:

\NewConfigure{subchpbreak}{1}\renewcommand\subchpbreak{\a:subchpbreak}\Configure{subchpbreak}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class='subchpbreak'>&\#167;</div>}}\Css{.subchpbreak{font-size:1.2em;}}

To allow configurability, we need to declare some hooks in which will be inserted html code. These hooks are inserted to redefined commands. In this case, we declared new configuration, subchpbreak with one hook, because your command takes no arguments. For commands one parameter, you would need two hooks, to be inserted before and after the parameter, for two parameters you would need three hooks and so on.

The hook is then inserted to redefined command, the hooks are named as \a:hookname, b:hookname, etc. In our case we use only one hook, so it is just \a:subchpbreak.

The hook is configured with

\Configure{subchpbreak}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class='subchpbreak'>&\#167;</div>}}

we need to use

\ifvmode\IgnorePar\fi\EndP

because <p> elements are inserted in each paragraph, but we don't want them around our <div>

You can add stuff to the .css file with the \Css command.

The resulting html:

<!--l. 15--><p class="noindent">&#8220;Alas, this is a quote,&#8221; said the idiot.</p>...</p><div class='subchpbreak'>§</div><!--l. 21--><p class="indent"> 

Image may be NSFW.
Clik here to view.
enter image description here

Regarding your problem with fonts, you should use \usepackage[T1]{fontenc} for best unicode support. When you use paratype fonts, you may see following message in the terminal output:

--- warning --- Couldn't find font `PTSerif-Regular-tlf-t1.htf'

for each font, .htf file must exist. I recently provided a solution for Droid sans, in your case you may create following PTSerif-Regular-tlf-t1.htf file:

.lm-echtfcss: PTSerif-Regular-tlf-t1 font-family: 'PT Serif', serif;

see the linked answer about Droid Sans for details. You may need to create similar files also for italic and bold fonts, if you use them.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles