Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape inline verbatim spaces in LaTeX output (\texttt) #1694

Closed
bjornbm opened this issue Oct 15, 2014 · 7 comments
Closed

Escape inline verbatim spaces in LaTeX output (\texttt) #1694

bjornbm opened this issue Oct 15, 2014 · 7 comments

Comments

@bjornbm
Copy link
Contributor

bjornbm commented Oct 15, 2014

Currently e.g. f . g is rendered to LaTeX as \texttt{f . g}. LaTeX in turn will treat the . as a regular sentence ending period and substitutes an em/quad(?) for the following space. Furthermore, multiple spaces in inline verbatim blocks are also discarded by LaTeX:

`f    . g`

becomes

\texttt{f    . g}

I would argue that neither of these are ever the desired behavior for verbatim text.

The solution appear to be to escape all spaces within the backticks, giving \texttt{f\ .\ g} and \texttt{f\ \ \ \ .\ g} for the above examples. This leaves automatic line breaking “intact”, where all \ at the break are replaced by a single line break. I think is reasonable behaviour for inline verbatim text.

@bjornbm
Copy link
Contributor Author

bjornbm commented Oct 16, 2014

I now note that highlighted code uses the \VERB{} environment, which does not allow automatic line breaking. Arguably you would want all white-space handling in verbatim text to be identical regardless of whether highlighting is on or not.

The quick and easy option there is to use \VERB{} instead of \texttt{} for inline verbatim code.

However, perhaps a more future-proof option to ensure that highlighted and non-highlighted verbatim text don't diverge would be to push both through the highlighting? Either by defaulting to an “empty language” for all verbatim text (inline and blocks) where no language is specified (along the lines of the proposal in jgm/highlighting-kate#40), or by faking it as was done in b371e83.

While it adds overhead, both in processing time and size of the output, simply pushing all verbatim text through the highlighter would be better as it avoids having to individually address other special cases similar to jgm/highlighting-kate#40 that may arise.

If this is preferred over my current pull request I could have a go at it, but as the change goes a bit “deeper” I won't speculatively invest the time. In that case I also think a new issue is warranted as the impact would not be limited to LaTeX output.

@jgm
Copy link
Owner

jgm commented Oct 16, 2014

Interesting idea, well worth considering. One reason for the present behavior was to avoid the need for the fancyvrb package if you're not using highlighting, but maybe that's not so important.

+++ Björn Buckwalter [Oct 16 14 02:37 ]:

I now note that highlighted code uses the \VERB{} environment, which does not allow automatic line breaking. Arguably you would want all white-space handling to be identical regardless of whether highlighting is on or not.

The quick and easy option there is to use \VERB{} instead of \texttt{} for inline verbatim code.

However, perhaps a more future-proof option to ensure that highlighted and non-highlighted verbatim text don't diverge would be to push both through the highlighting? Either by defaulting to an “empty language” for all verbatim text (inline and blocks) where no language is specified (along the lines of the proposal in jgm/highlighting-kate#40), or by faking it as was done in b371e83.

While it adds overhead, both in processing time and size of the output, simply pushing all verbatim text through the highlighter would be better as it avoids having to individually address other special cases similar to jgm/highlighting-kate#40 that may arise.

If this is preferred over my current pull request I could have a go at it, but as the change goes a bit “deeper” I won't speculatively invest the time.


Reply to this email directly or view it on GitHub:
#1694 (comment)

@bjornbm
Copy link
Contributor Author

bjornbm commented Oct 16, 2014

Unfortunately I'm not qualified to judge the severity of the fancyvrb dependency. Either way, I still think the pull request is good and worth pulling, if nothing else as an interim solution addressing the white-space problems while deferring the decision about going via the highlighter.

Now that you mention dependencies, I also seem to recall that highlighting (and the highlighting-kate dependency) used to be enabled (disabled?) with a cabal flag.

@mpickering
Copy link
Collaborator

Can this be merged @jgm ?

@jgm jgm closed this as completed in 7960013 Dec 10, 2014
@jdhao
Copy link

jdhao commented Sep 4, 2018

@jgm , I am using Pandoc 2.2.3.2. Now the space in inline code is escaped in the generated LaTeX source file. I wonder if there is a switch to turn this behavior off?

@jgm
Copy link
Owner

jgm commented Sep 4, 2018

Why would you want to turn it off? The escaping is important when you have consecutive spaces, and harmless in other cases.

@jdhao
Copy link

jdhao commented Sep 5, 2018

@jgm , I am using soul package in LaTeX to color the background of inline code (which is implemented using \texttt in LaTeX). I tried to redefine \texttt command and combine it with \hl command from the soul package.

Unfortunately, \hl command does not work well with escaped space (more info here). So I wonder if I can turn off this behavior of automatically escaping the space in inline code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants