Ask Your Question
1

Multiline string eats LaTeX tags due to backslash

asked 2 years ago

diana.davis gravatar image

updated 2 years ago

FrédéricC gravatar image

To create a multipage LaTeX document where each page is exactly the same except with a different name at the top, I want something like the following:

common_beginning = '{\bf To: '
list_of_names = ['Anna', 'Bev', 'Carlee']
common_end = """}

\footnotesize
This is small text.
\normalsize
Here is some more.
\newpage
"""

The issue is that when I compile the strings, I get:

common_beginning
'{\x08f To:'

common_end
'}\n\n\x0cootnotesize\nThis is small text.\n\normalsize\nHere is some more.\n\newpage\n'

In this example, it is eating the \b and the \f at the beginning of the LaTeX tags "\bf" and "\footnotesize". In my actual document, it eats the \n from "\newpage" and the \t from "\textwidth" as well. In any case, the backslashes really seem to mess things up. Is there a way around this?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 2 years ago

rburing gravatar image

updated 2 years ago

Use raw strings instead:

common_beginning = r'{\bf To: '

Or use escape sequences correctly:

common_beginning = '{\\bf To: '

(That is, write \\ to get a literal backslash.)

Preview: (hide)
link

Comments

1

Oh wow, I was just one keystroke from success. :) Thanks so much! It works perfectly now.

diana.davis gravatar imagediana.davis ( 2 years ago )

You're welcome! :)

rburing gravatar imagerburing ( 2 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2 years ago

Seen: 352 times

Last updated: Sep 18 '22