TransWikia.com

make4ht is removing blank lines from verbatim environment

TeX - LaTeX Asked on February 1, 2021

My LaTeX code file foo.tex:

documentclass{article}
usepackage{amsmath}
title{Demo}
begin{document}
begin{verbatim}
Foo

Bar

Baz
end{verbatim}
end{document}

Here is how I convert it to HTML using make4ht:

$ make4ht foo.tex
[STATUS]  make4ht: Conversion started
[STATUS]  make4ht: Input file: foo.tex
[STATUS]  make4ht: Conversion finished

Here is how foo.html looks:

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

   <pre id='verbatim-1' class='verbatim'>
Foo
Bar
Baz
</pre>
<!-- l. 11 --><p class='nopar'> </p> 
</body> 
</html>

The blank lines in verbatim environment have been removed in the HTML output. As a result the output looks different from what it would look if I had compiled the .tex file to a .pdf.

Is there a way to prevent make4ht from removing blank lines in verbatim environment?

One Answer

I think I've introduced this bug recently when I fixed another bug. I will fix it in TeX4ht immediately. Meanwhile, you can use the following configuration file, myconfig.cfg:

Preamble{xhtml}
Configure{verbatim}
{HCode{}}
{csname a:spendcsname}
begin{document}
EndPreamble

The Configure{verbatim} takes two parameters, the first one is code inserted at each line break, the second is a space character. csname a:spendcsname inserts non breaking space, which is necessary for correct indenting. HCode{} doesn't insert anything, but it forces tex4ht to insert line breaks at the correct places.

This was the HTML code before the change:

   <pre id='verbatim-1' class='verbatim'>
Foo
Bar 
Baz
</pre>

You can see that the linebreaks at the blank lines are missing.

Now compile your file with the configuration file:

make4ht -m draft -c myconfig.cfg filename.tex

You will get a correct HTML:

   <pre id='verbatim-1' class='verbatim'>
Foo

Bar

Baz
</pre>

Which is rendered like this:

enter image description here

Answered by michal.h21 on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP