My aim is to produce an html-file with the same text as the pdf produced by LaTeX- The html shall represent the pagination and line-break structure of the pdf: When there is a linebreak in the pdf I want to produce a <br> in html, when there is a paragraph I want to produce a <p> in html, when there is a newpage in the pdf I want to produce a horizontal line in html.

Handling of the paragraphs is easy since they are defined in the input file. But line-breaking and pagination depends on the font and on the width and height of the document (and maybe on some other things I cannot even imagine yet).

Is there a way of getting LaTex to tell me where it broke the lines and where it started a new page?

  • Not easily, you may find it easier to simply convert the pdf to html. But even if you preserve the line breaks justified text will not look justified unless you are using exactly the same fonts and same white space calculations. Commented Mar 2, 2015 at 12:29
  • 1
    The html does not need to appear as a kind of faksimile of the pdf, so the justified-issue is no problem. I just need the line-break and pagination structure for citation reasons. Commented Mar 2, 2015 at 12:52
  • 1
    oh OK, as I say it's not that easy, you could add \showoutput to the document then essentially all the information about where each character went is in the log file, but constructing any usable html from that format might be an interesting exercise. Commented Mar 2, 2015 at 13:00
  • a solution for the line breaking problem : create a vbox, use vsplit to create mini vbox of one line and export them with LuaLaTeX (see tex.stackexchange.com/q/228312/7712)
    – Maïeul
    Commented Mar 13, 2015 at 20:11

1 Answer 1


This latex:




Produces a log file showing the position of all the output:

LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.

Completed box being shipped out [1]
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
..\glue 25.0
..\glue(\lineskip) 0.0
...\hbox(6.94444+1.94444)x345.0, glue set 0.85849
....\OT1/cmr/m/n/10 L
....\OT1/cmr/m/n/10 o
....\OT1/cmr/m/n/10 r
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 m
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 p

So with a bit of perl (which might need to be made smarter in a real example) You can re-constitute the text adding the requested line and paragraph markup:

    if(m@^\.[^ ]* (.)\s*$@){
    print "$1";
    if (m@ligature ([^ ]*)\)\s*$@){
    print "$1";
    if(m@^\.*\\glue ([0-9.]*)@){
    print " " if ($1 > 2);
    print"\n<br>" if (m@\\baselineskip@);
    print"\n<p>" if (m@\\parskip@);

    print "\n\n<hr>\n\n" if (m@Completed box being shipped@);

then perl zz.pl zz.log > zz.html produces:

<br>fau-cibus. Morbi do-lor nulla, male-suada eu, pul-v-inar at, mol-lis ac, nulla. Cur-
<br>abitur auc-tor sem-per nulla. Donec var-ius orci eget risus. Duis nibh mi, congue
<br>eu, ac-cum-san eleifend, sagit-tis quis, diam. Duis eget orci sit amet orci dig-nis-sim
<br>Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
<br>auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultric

which looks like

enter image description here

  • actually this does need to be smarter, as shown it doesn't distinguish between discretionary hyphens that are taken and those that aren't but the latter should be easy to spot at the ends of lines... Commented Mar 13, 2015 at 20:17
  • That is cool. I wanted to do something similar (with python) but did not find the time to actually make it yet. But I have another problem: my original text has some special characters ("ä","ü","ö" for instance), which get lost by the log file. Do you have an idea how to solve it? In some way I have to find the letters in the .log-file back in the original .tex-file Commented Mar 13, 2015 at 21:17
  • 2
    @jonathan.scholbach two ways you can use a tcx file so the T1 encoded characters get writen as bytes rather than ^^ notation in the log, or change the perl where it picks up a character (.) and make it pick up (^^..) and in that case write out the html hex reference &#x$1; works so long as the T1 codepoint = Unicode, which it does in the Western European languages except for German ess-zed, so you'd have to fix that. Make sure you are not using OT1 as I do above. Or you could use xelatex or lualatex then the log will have unicode characters with the write codepoints Commented Mar 13, 2015 at 21:24

You must log in to answer this question.

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