5

I am trying to style tex4ht output using CSS in order to make a Kindle book. For example, I want to change the verse environment using .verse { margin-left:2.5em; white-space:normal; }

The Kindle guidelines ask for a single CSS file. When I use \CssFile in my .cfg file, the CSS goes at the start of the .css file, and so it is overridden by the CSS generated by tex4ht. I can edit it manually to move my CSS to the end, but I would love to find a way to do this that has as few manual steps as possible.

Changing a tex4ht css class seems to ask the same question, but wound up with quite a different answer.

Sorry not to post an MWE, but willing to do so if necessary.

1 Answer 1

2

There is some information about \CssFile usage in tex4ht documentation

You can include css files in the optional argument, multiple files must be delimited by commas. Place where css lines produced by tex4ht can be specified with line in /* css.sty */ format. Note that you must place \CssFile AFTER begin{document} in the .cfg file.

Now some sample, we have two css files sample.css:

body{color:green}

and hello.css:

/* css.sty */
body{width:30em;margin: 0 auto;}

we can then put into sample.cfg:

\Preamble{xhtml}
\begin{document}
\CssFile[sample.css,hello.css]
\EndCssFile
\EndPreamble

because line /* css.sty */ is in the second file, css generated by tex4ht is placed between contents of these two files:

/* sample.css from ahoj.tex (TeX4ht, 2014-09-20 17:00:00) */
  body{color:green}
/* start css.sty */
.cmtt-10{font-family: monospace;}
p.noindent { text-indent: 0em }
...
lot of lines
...
/* end css.sty */
body{width:30em;margin: 0 auto;}

and last warning: don't name any of these css files with same name as the TeX file, it would be overwritten then.

3
  • D'Oh! I am embarrassed I had mindlessly copied an example which had the /* css.sty */ at the end, skimming over its function in the documentation. Based on your response, I realized that I just needed to move the /* css.sty */ to the beginning of my CSS. Sorry to take so much of your time!
    – Nat Kuhn
    Sep 20, 2014 at 15:24
  • 1
    @NatKuhn it's ok, I didn't know that you can use `/* css.sty */ inside included css files, so I learned something new too
    – michal.h21
    Sep 20, 2014 at 15:41
  • Very kind of you!
    – Nat Kuhn
    Sep 20, 2014 at 16:09

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.