3

By default, TeX4ht breaks long lines of text in the input into shorter lines in the output HTML file. Is there any way to suppress these extra line breaks? (Note that I am trying to avoid extra line breaks in the source itself, not in the document that is ultimately displayed by the web browser.)

For example, suppose I start with the TeX source

\documentclass{article}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ante odio, condimentum ut nunc vel, rutrum rhoncus arcu. Praesent id justo tellus. Donec ut eros sagittis, bibendum augue id, luctus nulla. Aenean commodo ultrices turpis eget cursus. Pellentesque laoreet turpis leo, gravida laoreet libero sagittis sit amet. Fusce ut suscipit purus. Donec euismod dolor sit amet risus lacinia, ut pellentesque orci posuere. Morbi rutrum, sem ut elementum elementum, urna purus faucibus felis, vel rutrum mauris risus non erat. Proin commodo felis id mi feugiat rutrum. Cras et tempor massa. Donec tempor ante sed nibh varius, quis rutrum ipsum rutrum. Integer consectetur justo fermentum libero ultrices, eu fermentum nisl tempor.
\end{document}

If I then run htlatex, I get the following HTML as output:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd">  
<html > 
<head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<!-- html --> 
<meta name="src" content="test.tex"> 
<meta name="date" content="2013-10-02 14:03:00"> 
<link rel="stylesheet" type="text/css" href="test.css"> 
</head><body 
>
<!--l. 3--><p class="noindent" >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ante odio,
condimentum ut nunc vel, rutrum rhoncus arcu. Praesent id justo tellus. Donec ut
eros sagittis, bibendum augue id, luctus nulla. Aenean commodo ultrices turpis eget
cursus. Pellentesque laoreet turpis leo, gravida laoreet libero sagittis sit amet. Fusce
ut suscipit purus. Donec euismod dolor sit amet risus lacinia, ut pellentesque orci
posuere. Morbi rutrum, sem ut elementum elementum, urna purus faucibus felis, vel
rutrum mauris risus non erat. Proin commodo felis id mi feugiat rutrum. Cras et
tempor massa. Donec tempor ante sed nibh varius, quis rutrum ipsum rutrum.
Integer consectetur justo fermentum libero ultrices, eu fermentum nisl tempor.

</body></html> 

Notice that the single long line in the input has been broken into many short lines in the output. I would like it to instead appear as just a single line, as before.

(By the way, why do I care? Some content management systems (e.g., certain instances of WordPress) will automatically interpret newline characters in HTML as actual line breaks. Hence, the final rendered appearance of the document is wrong. One might argue that the real problem is with the CSS used in the content management system, but for a variety of reasons (permissions, backwards compatibility, etc.) modifying the CSS is often not a viable option.)

1 Answer 1

3

These line breaks come from the dvi file used in the conversion process. You can modify page dimensions, so there are no line breaks in the dvi file. For this purpose, you can use custom config file, so you don't have to touch your TeX source file.

file mycfg.cfg:

\Preamble{xhtml}
\textwidth=\maxdimen
\begin{document}
\EndPreamble

Unfortunately, there is a maximum limit for dimensions, so if your paragraph length is grater than this dimension, it will be break to more lines anyway.

Compile with

htlatex filename mycfg

Result:

<?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/)" /> 
<!-- html,xhtml --> 
<meta name="src" content="sample.tex" /> 
<meta name="date" content="2013-10-02 21:28:00" /> 
<link rel="stylesheet" type="text/css" href="sample.css" /> 
</head><body 
>
<!--l. 3--><p class="noindent" >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ante odio, condimentum ut nunc vel, rutrum rhoncus arcu. Praesent id justo tellus. Donec ut eros sagittis, bibendum augue id, luctus nulla. Aenean commodo ultrices turpis eget cursus. Pellentesque laoreet turpis leo, gravida laoreet libero sagittis sit amet. Fusce ut suscipit purus. Donec euismod dolor sit amet risus lacinia, ut pellentesque orci posuere. Morbi rutrum, sem ut elementum elementum, urna purus faucibus felis, vel rutrum mauris risus non erat. Proin commodo felis id mi feugiat rutrum. Cras et tempor massa. Donec tempor ante sed nibh varius, quis rutrum ipsum rutrum. Integer consectetur justo fermentum libero ultrices, eu fermentum nisl tempor. </p> 
</body></html> 
4
  • Great—that's a very simple solution. You can still run into trouble for paragraphs longer than a certain length, since "textwidth" has a maximum dimension (1638em on my machine, for whatever reason...)
    – Omega Tree
    Commented Oct 3, 2013 at 14:25
  • @TeXaN yes, I edited my answer to clarify this
    – michal.h21
    Commented Oct 3, 2013 at 14:54
  • In the question there is html header is different from what the answer shows the html header. Why there is a difference since I am facing the issues on the header in htlatex.
    – ssr1012
    Commented Jul 21, 2017 at 10:06
  • @ssr1012 the code in question comes from obsolete tex4ht version, because it points to WWW addresses which no longer exist
    – michal.h21
    Commented Jul 23, 2017 at 14:43

You must log in to answer this question.

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