1

I have a German document with snippets of code where I need the " symbol as it is. Normally, if I insert an empty space after it, I get it printed, but this does not always work:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\begin{document}

\texttt{inventar <- read\_excel(" inventar.xlsx")}

\end{document}

Generates:

enter image description here


For the record:

\texttt{inventar <- read\_excel(``inventar.xlsx'')}.

Typesets the following (two single quote chars):

enter image description here


Is there a pragmatic way I can print these quotes reliably?

5
  • You could use "{} but since that looks like code you should probably consider switching to some dedicated package (like listings, minted, ...).
    – campa
    Commented Jan 7, 2021 at 11:28
  • @campa That worked, indeed! I would not want to switch to listings because that is in-text.
    – Luis
    Commented Jan 7, 2021 at 11:31
  • 1
    Well, then you could just use verbatim (with \verb) instead of \texttt. In this way you don't have to escape stuff like the underscore.
    – campa
    Commented Jan 7, 2021 at 11:32
  • That is also true. Care to post it as an answer?
    – Luis
    Commented Jan 7, 2021 at 11:34
  • @JohnKormylo You get 2 single quote chars typeset, that would not work for a programming example.
    – Luis
    Commented Jan 7, 2021 at 16:11

1 Answer 1

3

ngerman makes " active to type Umlauts (and ß). If you don't have a lot of code (in which case I would recommend a dedicated package) use a simple \verb. Alternatively, if for some reason (e.g. the string appears in the argument of some other macro) you can add an empty group after " or use the macro \textquotedbl; for the latter you need the T1 font encoding but if you are writing in German that should be used anyway.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\begin{document}

Possible:
\texttt{inventar <- read\_excel("{}inventar.xlsx")}

Also possible:
\texttt{inventar <- read\_excel(\textquotedbl inventar.xlsx\textquotedbl)}

Much, much easier:
\verb+inventar <- read_excel("inventar.xlsx")+

\end{document}

enter image description here

6
  • I was also getting trouble with \verb{} because of the curly brackets, your example with the + delimiter is good. Learnt 2 things today, thank you!
    – Luis
    Commented Jan 7, 2021 at 11:42
  • 1
    @Luis \verb doesn't use braces: it uses the first character following it as delimiter. I used here + but you can use whatever you want. Of course, if your string involves a + you should use something else. The vertical pipe | is also often used.
    – campa
    Commented Jan 7, 2021 at 11:44
  • 1
    @Luis generally you cannot use {} with \verb, it needs the same char at both ends as its processing is very different than normal macros
    – daleif
    Commented Jan 7, 2021 at 11:44
  • @daleif Does that mean that I could use it as \verb{something{ ?
    – Luis
    Commented Jan 7, 2021 at 11:47
  • @Luis feel free to try
    – daleif
    Commented Jan 7, 2021 at 13:51

You must log in to answer this question.

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