Text FormattingImport result from Python into regular sentence

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
rotmat
Posts: 2
Joined: Sun Mar 20, 2022 10:48 pm

Import result from Python into regular sentence

Post by rotmat »

Hi
Im writing a book with Latex and looking for a way to import values calculated outside into a standard sentence.

Pythonscript:
Eriks birthday: 770101
Erik_age =today - 770101

Output from formatted Latexfile:
Erik is 45 years old

I want the age to be formatted as normal text. For the reader it shouldnt be visible that there was a calculation behind the age data.

There are a lot of examples where input is formatted as a table. But nothing on inserting data into normal text.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Import result from Python into regular sentence

Post by Bartman »

You could calculate the age of several people with Python and write the result in a text file. With the help of the datatool package, you could then select the value you are looking for and print it at the desired place.

Code: Select all

\begin{filecontents}{data.csv}
name,age
Erik,45
John,28
Mike,32
\end{filecontents}

\documentclass{article}
\usepackage{datatool}

\DTLloaddb{people}{data.csv}

\begin{document}
Erik is \DTLfetch{people}{name}{Erik}{age} years old.
\end{document}
rotmat
Posts: 2
Joined: Sun Mar 20, 2022 10:48 pm

Import result from Python into regular sentence

Post by rotmat »

Great! Exactly what Ive been looking for, Thanks!
Post Reply