I'm trying to get hebrew to pring into a pdf using pylatex. In a sample hebrew .tex file that I'm trying to emulate the format of, the header looks like this:

%\title{Hebrew document in WriteLatex - מסמך בעברית}

I was able to emulate this entire header except for the line \selectlanguage{hebrew}. I'm not sure how I should go about getting this in my .tex file using pylatex. The code for generating the rest of the file is:

doc = pylatex.Document('basic', inputenc = 'utf8x', lmodern = False, fontenc = None, textcomp = None)

    packages = [Package('babel', options = ['english', 'hebrew']), Package('inputenc', options = 'utf8enc')]
    doc.packages.append(Package('babel', options = ['english', 'hebrew']))

    doc.generate_pdf(clean_tex=False, compiler = "XeLaTeX ")

And the header of the .tex file generated is:


How do you get the selectlanguage line there? I'm pretty new to latex so I apologize for not being so accurate with my terminology.

1 Answer 1


It has been a little while since i used PyLaTeX, and it has done several large, breaking changes in the last few years.

But I believe:

doc.preamble.append(Command('selectlanguage', 'hebrew'))

should do it.

You could define SelectLanguage as an extension of CommandBase, but I don't think it is worth it, for a command you are only calling once.

So just use the generic Command(commandname, arg) function


You must log in to answer this question.

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