cnfgen.utils.latexoutput module

Output a LaTeX version of the CNF formula

The CNF formula is translated into the LaTeX markup language [1], using the names of the variable literally. The formula is rendered in the align environment, with one clause per row. Negated literals are rendered using the \neg command.

The output string is ready to be included in a document, but it does not include neither a preamble nor is nested inside \begin{document}\end{document}.

Note

By default the LaTeX document in output is UTF-8 encoded.

Examples

>>> from cnfgen.formula.cnf import CNF
>>> F=CNF([[-1, 2, -3], [-2, -4], [2, 3, -4]])
>>> print(to_latex_string(F))
\begin{align}
&       \left( {\overline{x}_1} \lor            {x_2} \lor {\overline{x}_3} \right) \\
& \land \left( {\overline{x}_2} \lor {\overline{x}_4} \right) \\
& \land \left(            {x_2} \lor            {x_3} \lor {\overline{x}_4} \right)
\end{align}
>>> F=CNF()
>>> print(to_latex_string(F))
\begin{align}
   \top
\end{align}

References

[1]http://www.latex-project.org/
to_latex_document(F, fileorname, export_header=True, extra_text='')

Output a LaTeX document describing the CNF formula

Parameters:
F : cnfgen.formula.cnf.CNF

cnf formula

fileorname: file object or string (or stdout if None)

destination file given either as object or as filename

export_header : bool, optional

determines whether the formula header should be inserted as a LaTeX comment in the output. By default is True.

extra_text : str, optional

Additional text attached to the abstract.

to_latex_string(F)

LaTeX string of the CNF formula

Parameters:
F : cnfgen.formula.cnf.CNF

cnf formula

Returns:
string

the string contains the LaTeX code