Ich filte die Zeilen einer LaTex-Datei wie folgt.
with open("fr_13_regions.tex",'r', ) as f:
targets = [line for line in f if line.startswith(("\\section", "\\subsection", "\\subsubsection", "\\begin", "\\end", "\\item"))]
Ich möchte das Ergebnis in einer neuen LaTex-Datei speichern. Ich habe das versucht:
>>> with open("fr_13_regions.tex", 'r', encoding = "utf-8") as f:
... targets = [line for line in f if line.startswith(("\\section", "\\subsection", "\\subsubsection", "\\begin", "\\end", "\\item"))]
... w=open("guru99.tex", "a+")
... w.write(str(targets))
...
13815
Aber es ist nur das Array schreiben. Es erstellt nicht wirklich eine neue Tex-Datei.
Hier ist ein Beispiel für die Datei fr_13_regions.tex :
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{newspaper}
\date{\today}
\currentvolume{1}
\currentissue{1}
\SetPaperName{%
\fontencoding{T1}\fontfamily{phv}\fontsize{26}{0}\bfseries
La France des 13 régions%
}
\SetPaperLocation{}
\SetPaperSlogan{Sous la direction de L. Carroué}
\SetPaperPrice{antoine.compagnie@gmail.com}
\usepackage{lipsum}
\begin{document}
\maketitle
\begin{multicols}{3}
\headline{Ile-de-France}
\section{La Région-capitale : une place et un rôle exceptionnels}
\subsection{Une longue construction historique}
VOila une belle histoire à raconter !
\end{document}