Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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> 
share|improve this answer
    
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...) –  TeXaN Oct 3 '13 at 14:25
    
@TeXaN yes, I edited my answer to clarify this –  michal.h21 Oct 3 '13 at 14:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.