How do I change the font to "helvetica" in pylatex ?

I tried it, but this does not worK:

doc = pylatex.Document(fontenc = 'helvet')
  • Welcome to TeX.SX! The font encoding has nothing to do with the font name. I do not know pylatex that well, but can't you simply include a font package (\usepackage in LaTeX)?
    – TeXnician
    Sep 23 '18 at 11:32
  • @TeXnician Thank you for your comment. This would be helpful, but I don't know how to do it in pylatex.
    – james
    Sep 23 '18 at 11:34
  • According to the docs it is possible to append packages and raw LaTeX strings, but as this solely revolves around Python and a library I'm voting to close as off-topic. Maybe you should simply ask the question how to include a package as issue.
    – TeXnician
    Sep 23 '18 at 11:41
  • 2
    Try doc.preamble.append(Command('usepackage', 'helvet')) in your python code.
    – Skillmon
    Sep 23 '18 at 12:16
  • @Skillmon Yes ! This works ! Thank you very much. I just had to add 'pl.' in front of 'Command' to make it work: 'doc.preamble.append(pl.Command('usepackage', 'helvet'))'
    – james
    Sep 23 '18 at 14:02

You can add stuff to your preamble using doc.preamble.append(). To add helvet to your preamble use:

doc.preamble.append(Command('usepackage', 'helvet'))

This needs

from pylatex import Command

to work out, if you imported pylatex and not only submodules and functions from it, use pylatex.Command instead.

From what I gathered by a quick look on the documentation of pylatex you might be able to add arbitrary stuff to your document (making a horizontal line possible) by doing:

from pylatex.utils import NoEscape

and then

doc.append(NoEscape(r'\hrule')) # or whichever macro you want to use for your horizontal line

I'm not sure what NoEscape is needed for, perhaps it isn't needed, but I can't try because I don't have pylatex installed.

  • This is great ! Thank you very much ! Just a quick question: How can I change the thickness of the line ? I tried "doc.append(pl.Command('rule','0.4pt','\linewidth'))" but it does not work.
    – james
    Sep 23 '18 at 14:33
  • I also tried: doc.append(NoEscape(r'\rule{\textwidth}{0.4pt}'))
    – james
    Sep 23 '18 at 14:34
  • @james I don't know and I can't test as I don't have it up and running. I tried to set it up but got an error just from importing it so I didn't investigate any further. In LaTeX you'd change the arguments of \rule to be greater than 0.4pt. You could try \rule{\textwidth}{1pt} for example.
    – Skillmon
    Sep 23 '18 at 15:08
  • If you do mean the thickness of the \hrule you can change it using \hrule width \textwidth height 1pt depth 1pt. It is a TeX primitive so has a very different syntax from \rule.
    – Skillmon
    Sep 23 '18 at 15:13
  • Thank you ! How would you translate the pure latex syntax "\rule{\textwidth}{1pt}" to the pylatex syntax ? BTW: just use pip install pylatex
    – james
    Sep 23 '18 at 15:15

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .