JelteF / PyLaTeX

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

Negative values in TextBlock #369

Open lukzapo opened 1 year ago

lukzapo commented 1 year ago

Encountered an issue where I wanted to pass a negative value for vertical_pos while calling TextBlock class.

TextBlock(width, horizontal_pos, vertical_pos)

Once a negative value was passed, dumps() would show that negative value as {-}123 instead -123 I found issue #144 and #276 which suggested to use NoEscape() however that not solved my issue at all. After digging into the code I found the issue in utils.py file.

While joining strings for TeX dumping in escape_latex() the function checks for specific LaTeX escape characters in _latex_special_chars' dictionary. Here the code finds that if '-' is encountered, it is supposed to be rendered as '{-}'. After removing this item from the dictionary all my code compiles just fine. I don't know exactly in what cases '-' has to be rendered with curly brackets, but so far I had no issues (and I use plenty of '-' for other functions etc.)

Could this bugfix be potentially further tested and implemented if it passes checks?