jgm / pandoc

Universal markup converter
https://pandoc.org
Other
33.96k stars 3.35k forks source link

LaTeX writer should use \hspace*{} for non-breaking spaces after line breaks #687

Closed jkr closed 11 years ago

jkr commented 11 years ago

Currently, the LaTeX writer will handle the following

 This line\
  \ \ \ \ that line

as

This line\\~~~~that line

The problem is that non-breaking spaces (tildes) don't work after a line break. There is some discussion of the approaches here: http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/WhiteSpace.html

The upshot is that after a manual line break, we need to indent with \hspace*{x}, where x is a unit of measure. Note the asterisk: regulare `\hspace' won't work in this context. I would suggest defaulting to 1em per non-breaking-space.

I didn't submit a pull request because there seemed like two possible ways of doing this:

  1. replacing all nbsp's this way. Probably overkill, and maybe not always what people mean.
  2. only replacing them after a LineBreak. I wasn't sure whether this would require adding a new boolean writer state to keep track of (stAtLineBreak or whatever). This seems pretty easy, and has the benefit of doing what people mean at the beginning of lines -- but changing the state seems like an intrusive change.

Whatever approach is taken, people do often seem to ask about indentation on the list (for poems especially) and are usually given something like the above advice. So we should probably make sure it works.

jgm commented 11 years ago

Thanks. I went with 0.4em, which seemed experimentally to be pretty close to what a regular ~ gives you.

+++ Jesse Rosenthal [Dec 19 12 07:17 ]:

Currently, the LaTeX writer will handle the following This line\ \ \ \ \ that line

as This line\~~~~that line

The problem is that non-breaking spaces (tildes) don't work after a line break. There is some discussion of the approaches here: [1]http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/WhiteSpace.html

The upshot is that after a manual line break, we need to indent with \hspace*{x}, where x is a unit of measure. Note the asterisk: regulare `\hspace' won't work in this context. I would suggest defaulting to 1em per non-breaking-space.

I didn't submit a pull request because there seemed like two possible ways of doing this:

  1. replacing all nbsp's this way. Probably overkill, and maybe not always what people mean.

    1. only replacing them after a LineBreak. I wasn't sure whether this would require adding a new boolean writer state to keep track of (stAtLineBreak or whatever). This seems pretty easy, and has the benefit of doing what people mean at the beginning of lines -- but changing the state seems like an intrusive change.

    Whatever approach is taken, people do often seem to ask about indentation on the list (for poem's especially) and are usually given something like the above advice. So it should probably work.

    -- Reply to this email directly or [2]view it on GitHub. [xJAuenYDiIoVt3LF3y684w3lSRHCmW5YMGx2EidPostD6A2E6fd15T9Uo4vNfCne.gif]

References

  1. http://www.maths.tcd.ie/%7Edwilkins/LaTeXPrimer/WhiteSpace.html
  2. https://github.com/jgm/pandoc/issues/687