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

\passthrough and babel #5696

Closed
waschk opened this issue Aug 21, 2019 · 16 comments
Closed

\passthrough and babel #5696

waschk opened this issue Aug 21, 2019 · 16 comments

Comments

@waschk
Copy link

waschk commented Aug 21, 2019

Converting an inline code starting with " like the Markdown `"string!"` to LaTeX will produce \passthrough{\lstinline'"string!"'}.
This works, unless you include it in a document, which uses a babel language that makes " an active character:

\documentclass{article}
\usepackage{listings}
\usepackage[ngerman]{babel}
\newcommand{\passthrough}[1]{#1}
\begin{document}
	\passthrough{\lstinline'"string!"'}
\end{document}

! Package Listings Error: lstinline ended by EOL.

The easiest solution would be to add " to the escaped characters. In fact, only if it is the first character if the passthrough it needs to be escaped:

\documentclass{article}
\usepackage{listings}
\usepackage[ngerman]{babel}
\newcommand{\passthrough}[1]{#1}
\begin{document}
	\passthrough{\lstinline'\"string!"'}
\end{document}

According to my tests, every character can be escaped. That would also make changing delimiters no longer required:

\documentclass{article}
\usepackage{listings}
\usepackage[ngerman]{babel}
\newcommand{\passthrough}[1]{#1}
\begin{document}
	\passthrough{\lstinline!\"string\!\"!}
\end{document}

The only exception to that seems to be the mathescape issue: #4716
When mathescape is set to true neither the dollar signs nor anything between them should be escaped.

edit: Removed the escaping of all character examples to make my actual point more clear.

@jgm
Copy link
Owner

jgm commented Aug 21, 2019

Not sure I like escaping all characters, as we like to make the LaTeX source human-readable and as elegant as possible given that it's machine generated.

@waschk
Copy link
Author

waschk commented Aug 21, 2019

I can understand that, that example was mostly an example. However, just adding " to the list will just delay the issue, until the next person comes along with a document in the esperanto language, trying to have an inline listing starting with ^.
My main point is, that it doesn't seem to break anything, as \" is normally the LaTeX command to make an umlaut. Escaping too much is a valid concern, but it doesn't seem to be an issue.

@adunning
Copy link
Contributor

Perhaps I'm not understanding what you're aiming to accomplish, but can you not simply add the shorthands=off option to Babel, as the default template does? This compiles without errors:

\documentclass{article}
\usepackage{listings}
\usepackage[shorthands=off,ngerman]{babel}
\newcommand{\passthrough}[1]{#1}
\begin{document}
	\passthrough{\lstinline'"string!"'}
\end{document}

@waschk
Copy link
Author

waschk commented Aug 21, 2019

That works, but it also means I can't use shorthands. Or I have to use \shorthandon{"} and \shorthandoff{"} to change that behaviour when required. Escaping the quotes is simpler and has no such side-effects on the rest of the document.

@adunning
Copy link
Contributor

I don't think the default output should be changed, given that it's not an issue with Pandoc's default configuration. Escaping so many characters would make the output much less readable for everyone. Possibly it could be an optional flag that would escape everything in all output formats?

@waschk
Copy link
Author

waschk commented Aug 21, 2019

Well, escaping so many characters is not required to fix it. In fact it is very rarely required. Only for the first character of the listing and only if it's a character that can be made active by babel, which should be the characters ^, ", :, ;, !, ?, and ~ depending on the selected language.
However, that is a very specific set of rules to fix a specific issue. Over the time several issues arised for some specific character like & and #. I think that code could be simplified by using a more general approach.

@adunning
Copy link
Contributor

That's certainly less onerous than the earlier suggestion of escaping everything.

@apblack
Copy link

apblack commented Apr 21, 2020

This issue has cropped up for me without babel. I have a (markdown) document with various non-ASCII Unicode characters in listing code, for example and . Pandoc produces

\passthrough{\lstinline!‹!}
\passthrough{\lstinline!≤!}

and so on. There are literate translations in the lstset such as {‹}{\guilsinglleft}1 to take care of printing the characters correctly. All this worked fine until recently.

Now, these constructions generate

! Package Listings Error: lstinline ended by EOL.

I can get rid of the error by removing the \passthrough, indicating that there is something fishy about the double macro substitution. With the \passthrough command in place, I can make these commands work by escaping the non-ASCII characters, that is, by writing

\passthrough{\lstinline!\‹!}

as described in this issue. I can't find any other workaround. Of course, since the latex file is produced by pandoc, this is not really a workaround at all ... in fact, I am stuck.

@fuhrmanator
Copy link

I would add the related tex.stackexchange question https://tex.stackexchange.com/q/557548/17868 where I tried to put a solution into the definition of \passthrough but I don't think it will work because the shorthands are already applied at the moment the argument is passed to the command (according to this answer).

@giuliboy
Copy link

I'm having the same issue.
Im using pandoc 2.10.1 to convert our .md files from wiki pages to pdf (xelatex).
Some of our devs use inline code "foo" like this and the conversion fails.

Error producing PDF.
! Package Listings Error: lstinline ended by EOL.
See the Listings package documentation for explanation.
Type H for immediate help.
...
l.545 ...ode block \passthrough{\lstinline!"foo"!}

My template from @Wandmalfarbe has the babel package included with "shorthands=off" option set.

I have tried to workaround the problem by different "renewcommand" attempts of \lstinline or under the hood functions but nothing works.
Disabling --listings resolves this problem, however i need listings to be enabled.

Are there any other workarounds that i could try?

@jgm
Copy link
Owner

jgm commented Sep 27, 2020

For reference, \passthrough was added in commit 730796e (see #1629).

Maybe there's a way to solve the problem that solved, wdthout using \passthrough?

That commit says:

This is because the characters %{}\ must be escaped
in lstinline when the listinline occurs in another
command, otherwise they must not be escaped.

If that's correct, it seems to contradict the suggestion above that everything can be escaped.

@giuliboy
Copy link

giuliboy commented Oct 4, 2020

For anyone having similar issues:
Thanks to malte (https://tex.stackexchange.com/questions/557548/how-can-i-automatically-do-shorthandoff-in-all-inline-listings-with-pandoc)
i have found a workaround for my particular issue:
i modified the Eisvogel Template slightly to explicitly shorthandOFF " (double quote).

%\newcommand{\passthrough}[1]{#1}
%workaround: explicitly disable " as shorthand character
\newcommand{\passthrough}{\shorthandoff{"}\passthroughtwo}
\newcommand{\passthroughtwo}[1]{#1\shorthandon{"}}

@pykong
Copy link

pykong commented Oct 4, 2020

@giuliboy Thanks for posting. I am struggling with the same error using the Eisvogel template.
Your workaround does not solve my problem though. Likely I am implementing it wrong.
Is there any chance you could submit your workaround as PR?

EDIT:
I may have misunderstood how generalizable that workaround might. In my updated understanding that workaround needs to be adapted to each specific use case. Hence, it might not be suitable ofr a PR.

The issue I was experiencing was due to a single inline code block ìnsert_df_into_fb, giving the following error message:

Error producing PDF.
! Package Listings Error: lstinline ended by EOL.

See the Listings package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.975 ...t\_df\_into\_fb!}, which is then executed

@giuliboy
Copy link

giuliboy commented Oct 7, 2020

@pykong
yes, my workaround is not suitable for a PR.
The workaround however did not work when the document language was set to "en" (lang: "en").
I then "escalated" the workaround with "languageshorthands{none}" :

\newcommand{\passthrough}{\languageshorthands{none}\passthroughtwo}
\newcommand{\passthroughtwo}[1]{#1}

this babel docu states:

Languages with no shorthands:
Croatian, English (any variety), Indonesian, Hebrew,Interlingua, Irish, Lower Sorbian, Malaysian, North Sami, Romanian, Scottish, Welsh
Languages with only"as defined shorthand character:
Albanian, Bulgarian, Danish,Dutch, Finnish, German (old and new orthography, also Austrian), Icelandic, Italian,Norwegian, Polish, Portuguese (also Brazilian), Russian, Serbian (with Latin script),Slovene, Swedish, Ukrainian, Upper Sorbian

Somehow the \shorthandoff(") did not do the trick when lang: en but the "sledgehammer" \languageshorthands{none} seems to work for me.

@pykong
Copy link

pykong commented Oct 14, 2020

@giuliboy THX!

@tarleb
Copy link
Collaborator

tarleb commented May 20, 2021

The default LaTeX template now disables all shorthands; as I understand it, that should resolve this issue. Custom templates might have to be adjusted in a similar fashion.

@tarleb tarleb closed this as completed May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants