1

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 - מסמך בעברית}
\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[english,hebrew]{babel}
\selectlanguage{hebrew}
\usepackage[top=2cm,bottom=2cm,left=2.5cm,right=2cm]{geometry}

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.append(text.decode('utf-8'))
    doc.generate_pdf(clean_tex=False, compiler = "XeLaTeX ")
    doc.generate_tex()

And the header of the .tex file generated is:

\documentclass{article}%
\usepackage[utf8x]{inputenc}%
\usepackage{lastpage}%
\usepackage[english,hebrew]{babel}%

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.