This is tex4ht issue only.

I use \begin{titlepage}...\end{titlepage} in some documents. After I started using p {text-align:justify; } in my configuration for tex4ht, I noticed now all the titles are shifted to the left also.

Title should remain centered on the page ofcourse. I have not been able to figure how to correct this. Here is a MWE and command used.




 \textbf{My most important book}\par 



This is my text


Compiled to pdf gives

enter image description here

Title is centered as expected. But

  make4ht  -ulm default -a debug foo.tex "htm,svg,nostyle"


enter image description here

You see, the title was treated as paragraph and shifted to left. If I remove \Css{p{text-align:justify;}} and recompile, this is the result

enter image description here

Next, I looked at the HTML generated to see if adding some CSS will fix this. Here is the HTML generated

<!DOCTYPE html> 
<html lang='en-US' xml:lang='en-US'> 
<meta charset='utf-8' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='width=device-width,initial-scale=1' name='viewport' /> 
<link href='foo.css' rel='stylesheet' type='text/css' /> 
<meta content='foo.tex' name='src' /> 

<!-- l. 8 --><p class='indent'>

</p><!-- l. 9 --><p class='indent'>

</p><!-- l. 9 --><p class='indent'>

<div class='center'>
<!-- l. 10 --><p class='noindent'>
</p><!-- l. 12 --><p class='noindent'><span class='ec-lmbx-12'>My most important book</span>
</p><!-- l. 15 --><p class='noindent'>September 29, 2023</p></div>

<!-- l. 18 --><p class='indent'>

</p><!-- l. 18 --><p class='indent'>

</p><!-- l. 22 --><p class='indent'>   This is my text

It says the title should be in <div class='center'> but for reason, once I added p{text-align:justify;} it no longer works. My CSS skills are limited to fix this.

How can one use p{text-align:justify;} but still keep title page centered?

Notice this only affects titlepage environment. If I use normal title with command \maketittle then the title remains centered no problem there.

TL 2023

1 Answer 1


Try this config file:

\ConfigureEnv{titlepage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="titlepage">}}
\Css{.titlepage p{text-align:center;}}

It encloses the contents of the titlepage environment in the <div class="titlepage"> element, and then, using CSS, it declares that every paragraph inside title page should be centered.

This is the result:

enter image description here

  • Thanks Micahl. I need to learn this trick to fix many other things I have also. Btw, what font there are you using for your HTML? I am now using font-family: Tahoma, Verdana, Segoe, sans-serif; which found to be nice. !Mathematica graphics But I also like the one you show in the image.
    – Nasser
    Sep 29, 2023 at 20:50
  • @Nasser it is the default font used by Firefox on my Fedora, Noto Serif.
    – michal.h21
    Sep 29, 2023 at 21:42
  • Thanks, will try "Noto Serif". I am learning the code you used. small question: When you did <div class="titlepage">, how do I insure that the name I give to the class, is not already used somewhere else? In this example, may be it is not important, as you used the same name as the environment, but if I create my own new class="123X" to use it later as you did, how does one know that "123X" is not already defined? I am trying to use your trick to fix few settings in the HTML. this part is not clear to me. Can I use any name? Or may be this will only work for known Latex environment name.
    – Nasser
    Sep 29, 2023 at 21:59
  • 1
    @Nasser the class names are usually based on the environment name, but if you want to be sure that your class names are unique, you can use some kind of prefix, like nasser-...
    – michal.h21
    Sep 29, 2023 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .