JelteF / PyLaTeX

A Python library for creating LaTeX files
https://jeltef.github.io/PyLaTeX/
MIT License
2.26k stars 287 forks source link

Using geometry_options creates error #301

Closed yuncu closed 4 years ago

yuncu commented 4 years ago

Hi,

Using geometry_options in Document creation, an additional "\geometry" command is created in tex file creating errors.

Most probably due to #299.

Best

JelteF commented 4 years ago

Can you share some code that breaks now, I guess the fix is indeed not good.

JelteF commented 4 years ago

Also, can you confirm that the 1.3.4 release doesn't have the issue?

yuncu commented 4 years ago

I am using 1.4.0 of PyLaTex and the issue does not exist in 1.3.4

This is from my code:

report = Document(documentclass="article", indent=False, document_options=["a4paper"], fontenc=None, inputenc=None, geometry_options=["this"])

In the tex file:

\usepackage{parskip}% \usepackage{geometry}% \geometry{this}%

What does \geometry command do?

JelteF commented 4 years ago

\geometry is supposed to apply the options in a way that works if \usepackage{geometry} was already used by another package: https://tex.stackexchange.com/a/412473/43228

What's your "this" in your case and what is the error you are getting?

JelteF commented 4 years ago

To be clear, the geometry tests that exist in the project pass fine with this change. So I think it might be related to your specific options.

yuncu commented 4 years ago

Actually, I'm using geometry_options=[] just to include the geometry package.

Error is shown in the line:

\usepackage{parskip}% \usepackage{geometry}% \geometry% \usepackage[turkish,noconfigs,shorthands=off]{babel}% <------

Error message:

Missing \endcsname inserted.

If I remove geometry_options=[] from Document constructor, geometry package is not included and the error disappears.

If I delete the \geometry line from tex file, error is not shown.

Maybe there is a problem between geometry and babel packages. Or \geometry command needs a default argument.

Thanks.

JelteF commented 4 years ago

So you gave an empty array to geometry_options before and that worked? But now it doesn't? If so, that edge case should be fairly easy to fix.

Meanwhile you can either use 1.3.4 or use document.packages.append(Package('geometry'))

yuncu commented 4 years ago

I'll go with the second option, thanks.