Matthias Pospiech
Matthias Pospiech

Reputation: 3488

curled brackets in .format

I want to print the following

\printCodeFromFile[5]{7}{myfile.tex}

which I construct with the following code

outputStr = "\\printCodeFromFile[{startline}]{{endline}}{{name}}".format(startline=lineStart, endline=lineEnd, name=filename)

That unfortunately comes out as

 \printCodeFromFile[5]{endline}{name}

So how would I escape or insert the curled brackets such that they are printed and the variable is inserted ? I could not find any hint in the docs.

Upvotes: 2

Views: 112

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1123630

Double the curly braces that you want to keep:

outputStr = "\\printCodeFromFile[{startline}{{{endline}}}{{{name}}}]".format(startline=lineStart, endline=lineEnd, name=filename)

Now you have doubled braces ({{ and }}) surrounding the replacement pattern ({endline} and {name}).

Upvotes: 8

Related Questions