The textext
plugin of Inkscape generates a .tex
file wrapper by means of the following piece of Python code (for v0.4.4
):
def tex_to_pdf(self, info):
"""
Create a PDF file from latex text
"""
# Read preamble
preamble = ""
if os.path.isfile(info.preamble_file):
f = open(info.preamble_file, 'r')
preamble += f.read()
f.close()
# If latex_text is a file, use the file content instead
latex_text = self._get_text(info)
# Geometry and document class
width = info.page_width
height = "400cm" # probably large enough
geometry = ""
document_class = r"\documentclass[a0paper,landscape]{article}"
if width:
document_class = r"\documentclass{article}"
geometry = (("\usepackage[left=0cm, top=0cm, right=0cm, nohead, "
"nofoot, papersize={%s,%s} ]{geometry}")
% (width, height))
if r"\documentclass" in preamble:
document_class = ""
# Write the template to a file
texwrapper = r"""
%(document_class)s
%(preamble)s
%(geometry)s
\pagestyle{empty}
\begin{document}
\noindent
%(latex_text)s
\end{document}
""" % locals()
f_tex = open(self.tmp('tex'), 'w')
try:
f_tex.write(texwrapper)
finally:
f_tex.close()
# Options pass to LaTeX-related commands
latex_opts = ['-interaction=nonstopmode', '-halt-on-error']
# Exec pdflatex: tex -> pdf
out = exec_command(['pdflatex', self.tmp('tex')] + latex_opts)
if not os.path.exists(self.tmp('pdf')):
raise RuntimeError("pdflatex didn't produce output:\n\n" + out)
You'll notice that it creates a file template resembling
%(document_class)s
%(preamble)s
%(geometry)s
\pagestyle{empty}
\begin{document}
\noindent
%(latex_text)s
\end{document}
that already creates the (document_class)
(as \documentclass{article}
) and (preamble)
(which may include a \documentclass
of your choice), all the way up to the start of the document. The only text inserted in your textext
dialog box should be what is inserted as (latex_text)
.
Since you included \documentclass[12pt]{article}
as your first input line, it ended forming part of the main document
\documentclass{article}
...
\begin{document}
\noindent
\documentclass[12pt]{article}% This is what you entered...
\begin{document}
test
\end{document}% ...up to here.
\end{document}
which causes the error.