Search code examples
latexpython-sphinxrestructuredtextpdflatex

How to make sphinx document via pdflatex \raggedright?


How can I render reST document with \raggedright command applied to all the text if I use pdflatex?


Solution

  • Use a custom template.

    In the following example, I'll be using xelatex. I would copy the default template for xelatex from /usr/local/lib/python2.7/site-packages/docutils/writers/latex2e/xelatex.tex to a file called mytemplate.tex

    The default template looks like this:

    $head_prefix% generated by Docutils <http://docutils.sourceforge.net/>
    % rubber: set program xelatex
    \usepackage{fixltx2e}
    \usepackage{fontspec}
    % \defaultfontfeatures{Scale=MatchLowercase}
    $requirements
    %%% Custom LaTeX preamble
    $latex_preamble
    %%% User specified packages and stylesheets
    $stylesheet
    %%% Fallback definitions for Docutils-specific commands
    $fallbacks$pdfsetup
    $titledata
    %%% Body
    \begin{document}
    $body_pre_docinfo$docinfo$dedication$abstract$body
    \end{document}
    

    You could add \raggedright just after \begin{document}.

    For rendering the document, I'd use the following commands:

    rst2xetex --template=mytemplate.tex --use-latex-docinfo mydoc.rst
    xelatex mydoc.tex
    xelatex mydoc.tex
    rm -f *.out *.aux *.log mydoc.tex
    

    (This is on a UNIX-like operating system.)