How to avoid braces in \usepackage generated with pylatex for package names containing "-"?

80 Views Asked by At

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?

1

There are 1 best solutions below

0
Lukas_peron On

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}"))