michal-h21 / make4ht

Build system for tex4ht
137 stars 15 forks source link

Using external css #81

Closed huijunchen9260 closed 2 years ago

huijunchen9260 commented 2 years ago

Dear Michal:

Is there any way that I can use -c myconfig.cfg to set up make4ht to use my own CSS file instead of the default one? I want to generate the file that is in the same style of my other webpage but not sure how to do it.

HJ

michal-h21 commented 2 years ago

Dear HJ,

the easiest way how to include a CSS is to use the AddCss configuration. See the documentation for more options. Simple use could look like this:

\Preamble{xhtml}
\Configure{AddCss}{custom.css} 
\begin{document}
\EndPreamble
huijunchen9260 commented 2 years ago

Sorry that I tried but it is still not working. Should I replace the custom.css into the path to the style.css that I want to use in the compilation? Or where should I "include" the style.css file?

michal-h21 commented 2 years ago

Yes, replace the custom.css with style.css, if that's the filename you use. You can also pass a subdirectory to this command, for example something like:

 \Configure{AddCss}{/css/custom.css} 

Which will work if you have a /css/custom.css file on your web server.

huijunchen9260 commented 2 years ago

This is pretty amazing. Now it is working.

michal-h21 commented 2 years ago

That's good to hear!

huijunchen9260 commented 2 years ago

I also try to follow the documentation to link to a CSS on some web but constantly failing:

make4ht -c config.cfg syllabus.tex
[STATUS]  make4ht: Conversion started
[STATUS]  make4ht: Input file: syllabus.tex
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ?    50   File ended while scanning use of \c:@HEAD:.
[ERROR]   htlatex: ?    52   LaTeX Error: Missing \begin{document}.
[ERROR]   htlatex: ?    60   Undefined control sequence.
[ERROR]   htlatex: ?    60   Undefined control sequence.
[ERROR]   htlatex: ?    64   LaTeX Error: Missing \begin{document}.
[ERROR]   htlatex: ?    64   LaTeX Error: Missing \begin{document}.
[ERROR]   htlatex: ?    69   Undefined control sequence.

and this is my config.cfg:

\Preamble{xhtml}
\Css{body{max-width:70ch;margin: 1rem auto;}}
\Configure{AddCss}{custom.css}
\Configure{@HEAD}{\HCode{<link type="text/css" href="https://huijunchen9260.github.io/style.css"/>}
% \Configure{AddCss}{../../../style.css}
\begin{document}
\EndPreamble
michal-h21 commented 2 years ago

Ah, it seems that there is a missing closing brace in the documentation! It should be:

\Configure{@HEAD}{\HCode{<link type="text/css" href="https://huijunchen9260.github.io/style.css"/>}}