2

I would like to incorporate tex4ht output into an existing web page. I'm wondering if there is a neat way to put the navigation bar and footer of said web page into every HTML file generated with tex4ht.

For example: can you tell tex4ht via a .cfg file to put certain HTML code at the beginning/end of the <body>?

1

You can use \Configure{BODY}{insert <body>}{insert </body>} configuration. Example:

\Preamble{xhtml}
\begin{document}
\Configure{BODY}          
   {\SaveEndP\IgnorePar 
       \HCode{\Hnewline<body \csname a:!BODY\endcsname
     >%
     <div class="header"><p>This is a header</p></div>
     }\ShowPar\par}
   {\IgnorePar\EndP\HCode{%
   \Hnewline<div class="footer"><p>This is a footer</p></div>\Hnewline
   \Hnewline</body>}
   \RecallEndP}%
\EndPreamble

There is some business related to paragraph handling involved, but what is important for your use case are \HCode commands, which are used to include HTML tags. You can also put text here, to insert line break, use \Hnewline command.

There is one issue with \HCode, you can't accented letters inside it's argument, it is best to use it only for tags including.

Sample document:

<?xml version="1.0" encoding="utf-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->  
<html xmlns="http://www.w3.org/1999/xhtml"  
> 
<head> <title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- charset=utf-8,html,xhtml --> 
<meta name="src" content="sample.tex" /> 
<link rel="stylesheet" type="text/css" href="sample.css" /> 
</head> 
<body ><div class="header"><p>This is a header</p></div> 
<!--l. 3--><p class="noindent" >hello world </p> 
<div class="footer"><p>This is a footer</p></div> 

</body> </html> 
| improve this answer | |
  • This works brilliantly, thank you. Just one further question: if I use the german umlaut ä in the header/footer, it's replaced by \protect \let \prOteCt \relax \Protect \csname acp:c\endcsname {23}a (similiarly for ö and ü). Putting umlauts in your MWE doesn't result in the same problem, so it must be something in my current setup. Do you have a suggestion where I should start searching the culprit? – Adrian Sep 6 '16 at 15:05
  • @Adrian try to move the accented letters outside the \HCode command. – michal.h21 Sep 6 '16 at 15:57

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.