0

I spend an hour on this and can't figure how to make tex4ht simply reduce the space between two paragraphs (at selected location, not globally for all the document).

I tried everything I know, which all work OK in pdf, but tex4ht just ignores all my latex commands to reduce the vertical space at that location.

This must be one of those things, where it works ok in PDF but not in tex4ht to HTML. Before I spend more time trying to see if I need to add direct HTML code to do this, I thought to ask. Here is MWE

\documentclass[11pt]{article}
\setlength\parindent{0pt}
\begin{document}

line one

line two

\vspace*{-.1in}
line three
\end{document}

in PDF, it works as expected:

Mathematica graphics

but make4ht bug.tex ignores it and gives this HTML

Mathematica graphics

HTML allows one to reduce vertical space, using something like p { margin-top: -20px; } or such as shown in number of places on the net. For example how-to-reduce-the-space-between-p-tags. I am not an expert in HTML nor CSS, that is why I use tex4ht to convert Latex to HTML so I do not have to write HTML.

Question is: Can one use latex commands to make tex4ht reduce vertical space at selected location, or does one need to insert some specific HTML code in that location to do so? And if so, how to do it?

Texlive 2016

which make4ht
/usr/local/texlive/2016/texmf-dist/scripts/make4ht/make4ht

HTML generated is

<?xml version="1.0" encoding="iso-8859-1" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->  
<html xmlns="http://www.w3.org/1999/xhtml"  
> 
<head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- xhtml,html --> 
<meta name="src" content="bug.tex" /> 
<link rel="stylesheet" type="text/css" href="bug.css" /> 
</head><body 
>
<!--l. 5--><p class="noindent" >line one
</p><!--l. 7--><p class="noindent" >line two
</p><!--l. 10--><p class="noindent" >line three </p> 
</body></html> 
  • given that most vertical spacing is somehow linked to page breaking choices and the page breaking in tex4ht is essentially non-existent ignoring vspace seems the most natural default. If you have vspace mid-document something is wrong anyway. – David Carlisle May 21 '17 at 22:24
  • @DavidCarlisle thank you. Your comment helped me see why tex4ht ignores these commands. I still would like to find a way to reduce the vertical spacing in the generated HTML at one location. Looks like I need to find a way to do this using HTML code inserted in the Latex document. – Nasser May 21 '17 at 22:38
  • it may well have a customisation to do something with negative vspace (it's a long time since I looked at tex4ht internals) I was just commenting that ignoring seems the most natural thing to do if ignoring page breaks. – David Carlisle May 21 '17 at 22:50
4

tex4ht doesn't support \vspace because it is used on quite a lot places in LaTeX macros and it could result in really bad HTML, if something was inserted at every place it is used. It is better to insert semantically meaningful tags and style the vertical spacing with CSS.

In your example, I would use some meaningful macro instead of direct \vspace use. It is then quite easy to redefine that macro when the document is processed by tex4ht to insert some HTML to do the job.

The package mycommands.sty:

\ProvidesPackage{mycommands}

\newcommand\negativespace{\vspace*{-.1in}}

\endinput

The configuration file mycommands.4ht:

\renewcommand\negativespace{\ifvmode\IgnorePar\fi\EndP\HCode{<p  class="negativespace"></p>}\par}
\Css{.negativespace{margin-top: -1em;padding:0;}}

\endinput

And modified TeX file:

\documentclass[11pt]{article}
\usepackage{mycommands}
\setlength\parindent{0pt}
\begin{document}

line one

line two

\negativespace
line three
\end{document}

results in following rendered HTML:

enter image description here

0

Here is a work around I found. This requires one to insert HTML code directly into the Latex document, since using Latex commands do not work for changing the vertical space.

\documentclass[11pt]{article}
\setlength\parindent{0pt}
\begin{document}

line one

line two

\ifdefined\HCode  %insert the paragraph inside HTML
\ScriptEnv{html}
{\NoFonts\hfill\break}
{\EndNoFonts}
\begin{html}
<p  style="margin-top: -1em">line three</p>
\end{html}
\else 
\vspace*{-.1in}
line three
\fi 

line four
\end{document}

Here is the HTML output

Mathematica graphics

Here is the generated HTML by tex4ht

make4ht foo.tex

<body>
<!--l. 5--><p class="noindent" >line one
</p><!--l. 7--><p class="noindent" >line two
</p><!--l. 13--><p class="noindent" >
<p  style="margin-top: -1em">line three</p>

</p><!--l. 21--><p class="noindent" >line four
</p> 
</body></html> 

It would have been ofcourse better to do this all in Latex, but in many cases, one has to resort to adding HTML or CSS to make tex4ht give similar output as the PDF.

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.