2

I would like to understand better what is responsible in Tex4ht for inserting the <p class="indent"></p> and <p class="noindent"></p> tag statements. I get a lot of empty ones by default with the following configuration:

\Preamble{3,charset=utf-8,html5,refcaption,sec-filename,sections+,svg,xhtml}

\DeclareGraphicsExtensions{.svg,.png,.jpg}

\Configure{maketitle}
    {\HCode{<section class="page-title"><div class="container-fluid text-center py-3">}\NoFonts}
    {\EndNoFonts\HCode{</div></section>}}
    {\HCode{<h1 class="title text-center">}}
    {\HCode{</h1>}
}

\Configure{@HEAD}
    {\HCode{
        <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css"/>\Hnewline
        <link rel="stylesheet" type="text/css" href="assets/css/custom.css"/>\Hnewline
    }}

\Configure{@BODY}
    {\HCode{
        <article class="page-content">
            <div class="container-fluid py-3">\Hnewline
                <div class="row">\Hnewline
                    <div class="col-md-2"></div>\Hnewline
                    <div class="col-md-8">\Hnewline
    }}

\Configure{@/BODY}
    {\HCode{
                    </div>\Hnewline
                    <div class="col-md-2"></div>\Hnewline
                </div>\Hnewline
            </div>\Hnewline
        </article>
    }}

\Configure{@/BODY}
    {\HCode{
        <footer class="page-footer">
            <div class="container-fluid text-center py-3">
                Copyright &copy; 2019 &hyphen; Cinematic Color Authors &hyphen;
                <a href="mailto:ves-tech-color@googlegroups.com">
                    ves-tech-color@googlegroups.com</a
                >
            </div>
        </footer>
    }}

\Configure{@/BODY}
    {\HCode{
        <script src="assets/js/jquery.min.js"></script>\Hnewline
        <script src="assets/js/popper.min.js"></script>\Hnewline
        <script src="assets/js/bootstrap.min.js"></script>\Hnewline
    }}

\ConfigureEnv{figure}
    {\HCode{<figure class="figure border d-block my-3 p-3"\Hnewline>}\bgroup\Configure{float}{\ShowPar}{}{}}
    {\egroup\HCode{</figure>}\ShowPar\par}
    {}
    {}

\Configure{IMG}
    {\HCode{<img class="figure-img img-fluid" src="}}
    {\HCode{" alt="}}
    {}
    {\HCode{"}}
    {\HCode{/>}}

\Configure{caption}
    {\HCode{<figcaption class="figure-caption"><span class="caption-name">}}
    {:\HCode{</span> }}
    {}
    {\HCode{</figcaption>}}

\Configure{graphics*}
    {svg}{
    {\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
    \Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg width="\csname Gin@req@width\endcsname"}
}

\ConfigureEnv{lstlisting}
    {\HCode{<div class="listing border d-block my-3 p-3">}}
    {\HCode{</div>}}
    {}
    {}

\begin{document}


\EndPreamble

I noticed that a naive search'n'replace from \HCode to \ifvmode\IgnorePar\fi\EndP\HCode in the configuration will get rid of most of them but 1) I would like to understand what I'm doing and where to put them properly 2) This might have unintended side effects.

I'm currently removing the empty ones by re-processing the HTML output with Python and Tidy.

3

As a general rule, you need to close the current paragraph before opening a block element, such as <figure> or <div>. It is especially important if the block element itself can contain multiple paragraphs. If it contains paragraphs, you also need to close them before the end tag.

I would edit your config file in the following way:

\Preamble{3,charset=utf-8,html5,refcaption,sec-filename,sections+,svg,xhtml}

\DeclareGraphicsExtensions{.svg,.png,.jpg}

\def\myendpar{\ifvmode\IgnorePar\fi\EndP}
\Configure{maketitle}
    {\myendpar\HCode{<section class="page-title"><div class="container-fluid text-center py-3">}\NoFonts}
    {\EndNoFonts\HCode{</div></section>}}
    {\HCode{<h1 class="title text-center">}}
    {\HCode{</h1>}
}

\Configure{@HEAD}
    {\HCode{
        <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css"/>\Hnewline
        <link rel="stylesheet" type="text/css" href="assets/css/custom.css"/>\Hnewline
    }}

\Configure{@BODY}
    {\myendpar\HCode{% container
        <article class="page-content">
            <div class="container-fluid py-3">\Hnewline
                <div class="row">\Hnewline
                    <div class="col-md-2"></div>\Hnewline
                    <div class="col-md-8">\Hnewline
    }}

\Configure{@/BODY}
    {\myendpar\HCode{
                    </div>\Hnewline
                    <div class="col-md-2"></div>\Hnewline
                </div>\Hnewline
            </div>\Hnewline
        </article>
    }}

\Configure{@/BODY}
    {\myendpar\HCode{
        <footer class="page-footer">
            <div class="container-fluid text-center py-3">
                Copyright &copy; 2019 &hyphen; Cinematic Color Authors &hyphen;
                <a href="mailto:ves-tech-color@googlegroups.com">
                    ves-tech-color@googlegroups.com</a
                >
            </div>
        </footer>
    }}

\Configure{@/BODY}
    {\HCode{
        <script src="assets/js/jquery.min.js"></script>\Hnewline
        <script src="assets/js/popper.min.js"></script>\Hnewline
        <script src="assets/js/bootstrap.min.js"></script>\Hnewline
    }}

\ConfigureEnv{figure}
    {\myendpar\HCode{<figure class="figure border d-block my-3 p-3"\Hnewline>}\bgroup\Configure{float}{\ShowPar}{}{}}
    {\myendpar\egroup\HCode{</figure>}\ShowPar\par}
    {}
    {}

\Configure{IMG}
    {\HCode{<img class="figure-img img-fluid" src="}}
    {\HCode{" alt="}}
    {}
    {\HCode{"}}
    {\HCode{/>}}

\Configure{caption}
    {\myendpar\HCode{<figcaption class="figure-caption"><span class="caption-name">}}
    {:\HCode{</span> }}
    {}
    {\HCode{</figcaption>}}

\makeatletter
\Configure{graphics*}
    {svg}{
    {\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
    \Picture[\csname a:GraphicsAlt\endcsname]{{\Gin@base.svg} \csname a:Gin-dim\endcsname}
}
\makeatother

\ConfigureEnv{lstlisting}
    {\myendpar\HCode{<div class="listing border d-block my-3 p-3">}}
    {\HCode{</div>}}
    {}
    {}

\begin{document}


\EndPreamble

You can see that I defined \myendpar macro, just to make the life a bit easier. It is not necessary to use it in every \Configure{@/BODY}, because the paragraphs have been closed by the first one.

This is a result on a sample file I created:

<!DOCTYPE html> 
<html lang="en-US" xml:lang="en-US" > 
<head>
   <title></title> 
<meta  charset="utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="viewport" content="width=device-width,initial-scale=1" /> 
<link rel="stylesheet" type="text/css" href="sample.css" /> 
<meta name="src" content="sample.tex" /> 
 <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css"/> 
<link rel="stylesheet" type="text/css" href="assets/css/custom.css"/> 
</head><body 
>
   <article class="page-content"> <div class="container-fluid py-3"> 
<div class="row"> 
<div class="col-md-2"></div> 
<div class="col-md-8"> 
    <section class="page-title"><div class="container-fluid text-center py-3">


<h1 class="title text-center">Hello world</h1>
<div class="author" >Michal</div><br />
<div class="date" >January 20, 2019</div>

   </div></section>
<!--l. 9--><p class="indent" >   Some text
</p>
   <figure class="figure border d-block my-3 p-3" 
>


<!--l. 13--><p class="noindent" >text
</p><!--l. 15--><p class="noindent" >  <img class="figure-img img-fluid" src="beacon.svg" alt="PIC" 
/>
</p>
<figcaption class="figure-caption"><span class="caption-name"><a 
 id="x1-21">Figure 1</a>:</span> caption text</figcaption>
another text

   </figure>
<!--l. 20--><p class="indent" >   no par
</p><!--l. 22--><p class="indent" >   more text
</p>
    </div> 
<div class="col-md-2"></div> 
</div> 
</div> 
</article>  <footer class="page-footer"> <div class="container-fluid text-center py-3"> Copyright &copy; 2019 &hyphen; Cinematic Color Authors &hyphen; <a href="mailto:ves-tech-color@googlegroups.com"> ves-tech-color@googlegroups.com</a > </div> </footer>  <script src="assets/js/jquery.min.js"></script> 
<script src="assets/js/popper.min.js"></script> 
<script src="assets/js/bootstrap.min.js"></script> 

</body> 
</html>

The TeX source:

\documentclass{article}

\usepackage{graphicx}
\title{Hello world}
\author{Michal}
\begin{document}
\maketitle

Some text

\begin{figure}

  text

  \includegraphics{beacon.svg}
  \caption{caption text}

  another text
\end{figure}
no par

more text

\end{document}
  • Awesome, this is crystal clear, I was also secretly hoping that you would answer as you are the John Skeet of tex.stackexchange :) – Kel Solaar Jan 21 at 4:11
  • @KelSolaar it is good that it is understandable, it was quite late and I was tired when I answered yesterday :) – michal.h21 Jan 21 at 9:42

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.