Ask Your Question
1

Multiline string eats LaTeX tags due to backslash

asked 2022-09-18 21:56:27 +0100

diana.davis gravatar image

updated 2022-09-19 08:51:48 +0100

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-09-18 22:37:53 +0100

rburing gravatar image

updated 2022-09-18 22:41:48 +0100

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.)

edit flag offensive delete link more

Comments

1

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

diana.davis gravatar imagediana.davis ( 2022-09-19 01:25:37 +0100 )edit

You're welcome! :)

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

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: 2022-09-18 21:56:27 +0100

Seen: 284 times

Last updated: Sep 18 '22