1

I need to create a LaTeX document with the package "tikz-feynman" in Python.

I use pylatex but, when I try to create the file like this

doc = Document("my_diagram")
doc.packages.append((Package("tikz-feynman", options=["compat = 1.0.0"])))
doc.append("Some text...")
doc.generate_tex()

it can't compile. This is because of a pair of braces in the name of the package tikz-feynman. When I run the code the .tex file has the header

\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[compat = 1.0.0]{tikz{-}feynman}%

instead of

\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[compat = 1.0.0]{tikz-feynman}%

How can I avoid those braces from occuring?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • What happens if you use `Package("{tikz-feynman}", ...)`? – mkrieger1 Apr 23 '23 at 19:35
  • the result becomes `\usepackage[compat = 1.0.0]{\{tikz{-}feynman\}}%` so the problem remains.. – Lukas_peron Apr 23 '23 at 20:44
  • Okay, that was just a guess. And what is the error message when trying to compile the document with `tikz{-}feynman`? Maybe that is correct after all. – mkrieger1 Apr 23 '23 at 20:46
  • Actually there is no error message. But when i compile the .tex without the braces it takes ~ 3.5 seconds, and with, even over 10 minutes it still compiling – Lukas_peron Apr 23 '23 at 20:50

1 Answers1

0

I've find a solution ! We can simple replace the line

doc.packages.append((Package("tikz-feynman", options=["compat = 1.0.0"])))

by

doc.preamble.append(NoEscape(r"\usepackage[compat=1.0.0]{tikz-feynman}"))