Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:47:39+00:00 2026-05-29T07:47:39+00:00

I have a LaTeX file I want to read in with Python 3 and

  • 0

I have a LaTeX file I want to read in with Python 3 and format a value into the resultant string. Something like:

...
\textbf{REPLACE VALUE HERE}
...

But I have not been able to figure out how to do this since the new way of doing string formatting uses {val} notation and since it is a LaTeX document, there are tons of extra {} characters.

I’ve tried something like:

'\textbf{This and that} plus \textbf{{val}}'.format(val='6')

but I get

KeyError: 'This and that'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:47:41+00:00Added an answer on May 29, 2026 at 7:47 am

    Method 1, which is what I’d actually do: use a string.Template instead.

    >>> from string import Template
    >>> Template(r'\textbf{This and that} plus \textbf{$val}').substitute(val='6')
    '\\textbf{This and that} plus \\textbf{6}'
    

    Method 2: add extra braces. Could do this using a regexp.

    >>> r'\textbf{This and that} plus \textbf{val}'.format(val='6')
    Traceback (most recent call last):
      File "<interactive input>", line 1, in <module>
    KeyError: 'This and that'
    >>> r'\textbf{{This and that}} plus \textbf{{{val}}}'.format(val='6')
    '\\textbf{This and that} plus \\textbf{6}'
    

    (possible) Method 3: use a custom string.Formatter. I haven’t had cause to do this myself so I don’t know enough of the details to be helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using LaTeX and I have a problem concerning string manipulation. I want
I have the following XML file with page nodes which I want to read
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
I have a LaTeX table that looks like this: \begin{table}[!ht] \centering \small \caption{ \bf{Caption}}
I have a large table I want to include in a LaTeX document. It
I would like to parse a self-designed file format with a FSM-like parser in
I have some simple text file. I am trying to read that file contents
I have a file in JSON format with record for individual users. Some of
I have something like this: char *current_day, *current_time; system(date +%F); system(date +%T); It prints
I want to read in mulitple files from a directory and store each value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.