2

When running htlatex <filename> one can include CSS code via \CssFile and \EndCssFile. This works fine as long as the code is included directly in the main document body.

I suspect this is the usual problem of including verbatim content in a macro, but is there a way to include CSS code but not have to put it in the actual document body.

Notes:

  • pfdlatex runs fine on both of these, problem is only with htlatex in the second MWE below.
  • The CSS included is not really used in the HTML to be generated from this MWE.

Code: Works, but document is cluttered

\documentclass{article}
\usepackage{ifpdf}

\begin{document} %% This works, but would rather it not be here so that the document is not cluttered. \ifpdf \else \CssFile /* css.sty */ .imageWrapperHi { height:99%; width:100%; text-align:center; page-break-inside:avoid; } .imageWrapperHi img { display:inline-block; height:100%; margin:0 auto; }
\EndCssFile \fi % ------- Some text. \end{document}


Code: Desire a solution such as this

\documentclass{article}
\usepackage{ifpdf}
\usepackage{etoolbox}

\ifpdf \else \AfterEndPreamble{% \CssFile /* css.sty */ .imageWrapperHi { height:99%; width:100%; text-align:center; page-break-inside:avoid; } .imageWrapperHi img { display:inline-block; height:100%; margin:0 auto; }
\EndCssFile }% \fi % -------

\begin{document} Some text. \end{document}

Peter Grill
  • 223,288

1 Answers1

3

You should use .cfg file for this stuff, it is really not needed to clutter your documents with tex4ht configurations. It works with following file, hello.cfg:

\Preamble{xhtml}
\begin{document}
\CssFile 
/* css.sty */ 
.imageWrapperHi { height:99%; width:100%; text-align:center; page-break-inside:avoid; }
.imageWrapperHi img { display:inline-block; height:100%; margin:0 auto; }  
\EndCssFile
\EndPreamble

compile with

htlatex filename hello

for some information see this answer

michal.h21
  • 50,697