# Multiline string eats LaTeX tags due to backslash

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?

edit retag close merge delete

Sort by » oldest newest most voted

common_beginning = r'{\bf To: '


Or use escape sequences correctly:

common_beginning = '{\\bf To: '


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

more

1

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

( 2022-09-19 01:25:37 +0100 )edit

You're welcome! :)

( 2022-09-19 12:49:57 +0100 )edit

## Stats

Seen: 51 times

Last updated: Sep 18 '22