PythonTex 和 Beamer

PythonTex 和 Beamer

我尝试使用 Python 代码构建一个 Beamer 演示文稿:

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetheme{Madrid}

\usepackage{pythontex}
\usepackage{amsmath,graphicx}

\begin{document}

\begin{frame}
    \frametitle{}

\begin{pycode}
from sympy import *

var("x,y")      # Define symbolic variables
expr = (x + y)**3  # Define an expression

# print it with latex
print(r" \begin{equation}"
   + latex(expr)+"="+latex(expand(expr))
   + "\end{equation}" )
\end{pycode}    

\end{frame}
\end{document}

并编译为:

pdflatex -synctex=1 -interaction=nonstopmode *.tex
pythontex --interpreter python:python3 *.tex
pdflatex -synctex=1 -interaction=nonstopmode *.tex

相同的 Python 代码在scrartcl和中运行,article但在 beamer 上我得到了这个:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./document.tex
LaTeX2e <2017-04-15>

....

(/usr/share/texlive/texmf-dist/tex/latex/currfile/currfile.sty
(/usr/share/texlive/texmf-dist/tex/latex/filehook/filehook.sty)))
(./document.aux
! Undefined control sequence.
l.19 \abx@aux@refcontext
                        {nty/global//global/global}

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.19 \abx@aux@refcontext{n
                          ty/global//global/global}
) (/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/grfext.sty)
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
ABD: EveryShipout initializing macros
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./document.out) (./document.out)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-basic-dictionary
-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-bibliography-dic
tionary-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-environment-dict
ionary-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-months-dictionar
y-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-numbers-dictiona
ry-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-theorem-dictiona
ry-English.dict) (./pythontex-files-document/document.pytxmcr)
(./pythontex-files-document/document.pytxpyg) (./document.nav

! LaTeX Error: No counter 'refsection' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1 \defcounter {refsection}{0}
                               \relax

! LaTeX Error: No counter 'refsection' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3 \defcounter {refsection}{0}
                               \relax

! LaTeX Error: No counter 'refsection' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.5 \defcounter {refsection}{0}
                               \relax

! LaTeX Error: No counter 'refsection' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.7 \defcounter {refsection}{0}
                               \relax
)
! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again> 

l.26 \end{frame}

Runaway argument?
from sympy import * 
! Paragraph ended before \FV@BeginScanning was complete.
<to be read again> 
                   \par 
l.26 \end{frame}

! You can't use `macro parameter character #' in horizontal mode.
\beamer@doifinframe ...import * \par var("x,y") ##
                                                   Define symbolic variables...
l.26 \end{frame}

! You can't use `macro parameter character #' in horizontal mode.
\beamer@doifinframe ...iables expr = (x + y)**3 ##
                                                   Define an expression \par...
l.26 \end{frame}

! You can't use `macro parameter character #' in internal vertical mode.
\beamer@doifinframe ...efine an expression \par ##
                                                   print it with latex print...
l.26 \end{frame}

(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd)
! Bad space factor (0).
<recently read> \@savsf 

l.26 \end{frame}


Underfull \vbox (badness 10000) has occurred while \output is active [1{/var/li
b/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] (./document.aux) )
(see the transcript file for additional information) </home/user/.texlive2017/t
exmf-var/fonts/pk/ljfour/jknappen/ec/ecsi1095.600pk> </home/user/.texlive2017/t
exmf-var/fonts/pk/ljfour/jknappen/ec/ecss0600.600pk> </home/user/.texlive2017/t
exmf-var/fonts/pk/ljfour/jknappen/ec/ecss1095.600pk></usr/share/texlive/texmf-d
ist/fonts/type1/public/amsfonts/cm/cmss10.pfb>
Output written on document.pdf (2 pages, 25932 bytes).
SyncTeX written on document.synctex.gz.
Transcript written on document.log.
This is PythonTeX 0.16

--------------------------------------------------
PythonTeX:  document - 0 error(s), 0 warning(s)

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./document.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 12 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/beamer/beamer.cls
Document Class: beamer 2018/02/20 v3.50 A class for typesetting presentations

....

(/usr/share/texlive/texmf-dist/tex/latex/currfile/currfile.sty
(/usr/share/texlive/texmf-dist/tex/latex/filehook/filehook.sty)))
(./document.aux) (/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/grfext.sty)
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
ABD: EveryShipout initializing macros
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./document.out) (./document.out)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-basic-dictionary
-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-bibliography-dic
tionary-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-environment-dict
ionary-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-months-dictionar
y-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-numbers-dictiona
ry-English.dict)
(/usr/share/texlive/texmf-dist/tex/latex/translator/translator-theorem-dictiona
ry-English.dict) (./pythontex-files-document/document.pytxmcr)
(./pythontex-files-document/document.pytxpyg) (./document.nav)
! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \iterate.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again> 

l.26 \end{frame}

! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again> 

l.26 \end{frame}

Runaway argument?
from sympy import * 
! Paragraph ended before \FV@BeginScanning was complete.
<to be read again> 
                   \par 
l.26 \end{frame}

! You can't use `macro parameter character #' in horizontal mode.
\beamer@doifinframe ...import * \par var("x,y") ##
                                                   Define symbolic variables...
l.26 \end{frame}

! You can't use `macro parameter character #' in horizontal mode.
\beamer@doifinframe ...iables expr = (x + y)**3 ##
                                                   Define an expression \par...
l.26 \end{frame}

! You can't use `macro parameter character #' in internal vertical mode.
\beamer@doifinframe ...efine an expression \par ##
                                                   print it with latex print...
l.26 \end{frame}

(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd)
! Bad space factor (0).
<recently read> \@savsf 

l.26 \end{frame}

[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./document.aux) )
(see the transcript file for additional information)pdfTeX warning (dest): name
{Navigation2} has been referenced but does not exist, replaced by a fixed one

 </home/user/.texlive2017/texmf-var/fonts/pk/ljfour/jknappen/ec/ecss0600.600pk>
 </home/user/.texlive2017/texmf-var/fonts/pk/ljfour/jknappen/ec/ecsi1095.600pk>
 </home/user/.texlive2017/texmf-var/fonts/pk/ljfour/jknappen/ec/ecss1095.600pk>
</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmss10.pfb>
Output written on document.pdf (1 page, 24108 bytes).
SyncTeX written on document.synctex.gz.
Transcript written on document.log.

这是 pdf 结果:

结果

答案1

我怀疑这是多种问题的综合结果。

  • 前几条错误消息看起来像是以前使用时的一些残留biblatex

    -> 删除所有辅助文件并重新编译

  • 所有其他错误消息都是由于在普通框架中使用脆弱内容(如源代码)引起的

    -> 使用[fragile]框架选项

无关:

你不需要graphicx使用投影仪

相关内容