Git Product home page Git Product logo

sphinx_latex's Introduction

Custom LaTeX and HTML builders for Sphinx - Python documentation tool

This is code contains LaTeX and HTML builders for Sphinx - the Python default documentation tool which uses the ReStructuredText (RST) file format. It allows for custom build LaTeX documents: you can define your own LaTeX preambule, e.g. use whatever class you would like to use (for example the memoir class). Also adds a few LaTeX type directives (align, theorem, definition, etc)

Installation

To install the extension follow the standard way, i.e. put the python files somewhere in your $PYTHONPATH and add "clatex_builder" to extensions list in your conf.py file.

options

The following options are recognised in the conf.py file:

clatex_documentclass

String option with the default value: \documentclass{book}\n: note that it should provide whole document class command, not just the document class name. In this way you can control document class options.

clatex_preambule

LaTeX preambule used added to the LaTeX source files. It should not contain only the document class statement. This plugin will only add a minimal set of needed LaTeX packages: hyperref, longtable, tabluary, multirow and possibly makeidx package. You can also add the attached tex/fresh.sty package. It is a simpler version of the original sphinx.sty package. It does not use \bf and \rm commands (which are not always defined, c.f. memoir). For more information see the package itself.

clatex_use_chapters

this is a boolean option with the default value True. If False the major section unit will be \section (what is useful for the article document class).

clatex_begin_doc

By default it is an empty string. The value of this option will be added just after \begin{document} into the LaTeX source file.

clatex_end_doc

By default it is an empty string. The value of this option will be added just before \end{document}.

clatex_highlighter

Boolean options, by default True. If True a code highlighter will be inserted into LaTeX preambule. You can turn it off if you are not writing computer related stuff where you do not need to highlight code snippets.

clatex_hyperref_args

String options, by default an empty string. List of options added to the command \usepackage[...]{hyperref}.

clatex_makeidx

Boolean option, by default False. If True will add just \usepackage{makeidx}\n\makeindex into the preamble. If it is a string the string will be added (in this way you can add options to the \usepackage{makeidx} command. You can use clatex_end_doc to insert the \printindex command - it is not added by default!

theorems and newtheorem function

Furthermore it allows you to define LaTeX like environments and use them in the rst source files. There are predefined directives:

.. theorem::

.. proposition::

.. definition::

.. lemma::

.. example::

.. exercise::

The directives work in a very similar way to the corresponding LaTeX environment: they all are numbered. You can define your own environment. For that you need to add your own extension to Sphinx and add the following code to the setup function:

def setup(app)

    newtheorem(app, 'theorem', 'Theorem', 'theorem')

The newtheorem() function works in a very similar way to the LaTeX \newtheorem{}{}{} command. That means that the above code will define a .. theorem:: directive, which will use Theorem as the environment name and the directives will be numbered like theorem (the third argument). For example if you add also

    newtheorem(app, 'definition', 'Definition', 'theorem')

All the definition directives will be counted together with theorem directives. There is currently no way to bind the numbering with the section numbers (like Definition 1.1, 1.2 in the first chapter; 2.1, 2.2, ... etc in the second one) - but I have started working on this and I have an idea how to implement it - though it requires some effort.

The syntax for the directive is very similar to

\begin{theorem}[title]
    ...
\end{theorem}

the equivalent usage of theorem directive is:

.. theorem:: title

    ...

environment directive

Furthermore, there is an environment directive which allows for more sophisticated constructions:

.. environment::
    :class: ENV_CLASS
    :name: Definition
    :html_title: title used by html builder
    :latex_title: title used by latex builder

	...

You can also use :title: which if both :html_title: and :latex_title: are ought to be the same. This directive will probably be changed in future releases.

textcolor role

You can also change the color with the :textcolor: role:

:textcolor:`<color_spec> colored text`

The color_spec is an HTML color model, e.g. #ffffff for white, #00ff00 for green, etc. The LaTeX builder is using \textcolor[HTML]{color_spec}{colored text} (with the # removed from color_spec). The HTML builder is using

<font color="color_spec">colored text</font>

to change the font color.

endpar directive

The .. endpar:: directive will input
into HTML and an empty line into LaTeX source file - which ends a paragraph in LaTeX.

align directive

There is also align directive which aligns the code:

.. align:: center

    Centered text

.. align:: flushleft

    Left aligned text

.. align:: flushright

    Right aligned text

You can also use 'left' and 'right' instead of 'flushleft' and 'flushright'.

sphinx_latex's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sphinx_latex's Issues

builder crash

I am compiling a fairly large Sphinx documentation with latex and I got this error

Exception occurred:
File "/usr/local/lib/python2.7/dist-packages/sphinx/writers/latex.py", line 363, in visit_document
self.body.append(BEGIN_DOC % self.elements)
KeyError: 'begin_doc'
The full traceback has been saved in /tmp/sphinx-err-MCa61D.log, if you want to report the issue to the developers.

any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.