如何使用 Inkscape 的 textext 插件

如何使用 Inkscape 的 textext 插件

我在使用 inkscape 中的 textext 插件时遇到了麻烦;即使是最简单的代码,例如

\documentclass[12pt]{article}
 \begin{document}

test

\end{document}

给出了如下错误:

LaTeX Warning: Unused global option(s): [a0].
No file tmp.aux.
! LaTeX Error: Can be used only in preamble.
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
l.7         \documentclass
                          [12pt]{article}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on tmp.log.

我究竟做错了什么?

答案1

textext插件Inkscape.tex通过下面的 Python 代码生成文件包装器(对于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)

你会注意到它创建了一个类似于

    %(document_class)s
    %(preamble)s
    %(geometry)s
    \pagestyle{empty}
    \begin{document}
    \noindent
    %(latex_text)s
    \end{document}

已经创建了(document_class)(作为\documentclass{article})和(preamble)(可能包括\documentclass您选择的 ),一直到文档的开头。对话框中插入的唯一文本textext应该是插入为 的内容(latex_text)

由于您将\documentclass[12pt]{article}其作为第一行输入,因此它最终成为主文档的一部分

\documentclass{article}
...
\begin{document}
\noindent
  \documentclass[12pt]{article}% This is what you entered...
  \begin{document}
  test
  \end{document}% ...up to here.
\end{document}

这会导致错误。

相关内容