4

I stumbled into the following sample

\documentclass[a4paper,11pt]{article}
\usepackage[english, ngerman]{babel}
\begin{document}
Quick test - not yet bold

"\textbf{Bold text for test - part 2} 

Continue -without bold???

"{\bfseries Bold text for test} 

Now again - without bold???

\end{document}

Is there a simple explanation why the bold text for the first statement (\textbf) terminates properly while the second (\bfseries) fails? I figured it out that it is related with the quote and the language setting. But I have no clue why in specific it fails.

enter image description here

2
  • 6
    The quote is an active char with ngerman, don't use "{, you see that it has interesting side effects. If you want real quotes, use e.g. \glqq, or the csquotes package. Mar 10, 2020 at 9:53
  • This sounds in general like a good idea. The major problem I have is that the beginning and the ending of the quote has different characters (commands) - while the input is same ("). Which makes my whole use case quite messy.
    – LeO
    Mar 11, 2020 at 10:33

2 Answers 2

6

The German module for babel makes " into a shorthand. This shorthand is implemented as a one-argument macro, because it's necessary to know what comes along and decide what to do: for instance "a will produce “ä”, "s yields “ß” and "| disables a ligature at the spot.

In the case of "{...}, the entire contents inside the braces is the argument, which obviously doesn't match any of the predefined shorthands, so LaTeX will deliver a standard double quote (precisely, the character in the ASCII position of " in the current font) and the tokens grabbed as an argument, but with braces removed (this is a low level TeX feature).

Thus what happens is that the braces are interpreted as the delimiters for an argument, not as group delimiters. Since they're removed, boldface goes on forever.

If you want German style quotes, use

,,text``

or

„text“
4
  • Yeah, thx for the explanation. I think the perfect workaround in this situation is to use a \nop command. This works as expected. I wouldn't have thought on this solution without your explanation. The usage of the German style quotes has the real problem that the text is somehow autogenerated an a replace seems tricky (beginning and ending quotes, what happens if they are not properly closed, etc.)
    – LeO
    Mar 10, 2020 at 14:02
  • @Leo it's better to add the workaround as a separate answer instead of an edit to this answer. Edits to an answer are used for clarification, not to add substantially different approaches, especially when you edit an answer written by someone else.
    – Marijn
    Mar 10, 2020 at 14:17
  • @LeO Why bother with \nop? If you really want "{\bfseries (which I don't believe), type "\relax{\bfseries
    – egreg
    Mar 10, 2020 at 14:28
  • @Marijin: yeah, correct. Sorry didn't want to harm. My intention was just to add one note with a conclusion how to make out of the theoretical basics a solution. To egreg: thx for the additional hint. I don't really understand why you doubt, but anyway thx.
    – LeO
    Mar 10, 2020 at 16:59
1

After having an idea about what's going on behind the scene I thought in a first place that

"\relax{\bfseries  Bold text for test} 

is a good approach. Since I need the approach in different scenarios I finally found

"\bgroup{}\bfseries Bold text for test\egroup{}"

which seems quite similar but has the advantage to solve my other issue as well.

You must log in to answer this question.

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