0

I'm trying to change a font size at some arbitrary point in my document, and I'm using pylatex to create the file. I've gotten it to change manually by putting after the header:

\begin{document}%
\fontsize{15}{12}\selectfont

However when pylatex creates the file it puts in:

\begin{document}%
\normalsize%
\fontsize{15}{12}%

I've manually tested it by taking our \normalsize% and the font changes. How do I get rid of `normalsize? Also, is there a better way to do this?

Here's my code:

    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.preamble.append(pylatex.Command('selectlanguage', 'hebrew'))
    doc.append(pylatex.Command('fontsize', arguments = ['15', '12']))
    doc.append(text[0].decode('utf-8'))
    doc.append(pylatex.Command('selectlanguage', 'english')) 
    doc.append(text[1].decode('utf-8'))
    doc.generate_pdf(clean_tex=False, compiler = "pdflatex ")
    doc.generate_tex()
  • Welcome! What are you trying to do exactly? Are you trying to change the default document font size? This is the wrong way to do it. Are you trying to change the size for some specific part of the text? This is the wrong way to do it. However, the right ways are different in the two cases. Can you provide a minimal .tex document showing what you want to do? – cfr Aug 9 '17 at 22:57
  • What happens to the \selectfont? Does the wrapper throw that away for some reason? That seems rather problematic. – cfr Aug 9 '17 at 22:58
  • @cfr I'm trying to change the font size for a specific part of the document. One paragraph will be one font size and the next would be a different font size. Sorry if that wasn't clear. – David Aug 10 '17 at 1:43
  • With \fontsize{15}{12} you get a 15pt font over a baseline skip of 12pt, so you will get variability in the distance between the baselines depending on ascenders or descenders. Have you a particular reason for doing so? – egreg Aug 11 '17 at 8:18
1

You need to change the pylatex.Document arguments to:

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

in order to remove the normalsize line.

To put the fontselect in place a command for it after the command for fontsize like this:

doc.append(pylatex.Command('fontsize', arguments = ['15', '12']))
doc.append(pylatex.Command('selectfont'))

The font size will then be 15.

  • 1
    This isn't a good approach. If you want your entire document to be that size (or want it as default), use a class which supports extended font sizes. Otherwise \large will not do as it should, for example. – cfr Aug 11 '17 at 0:29

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.