我在 Lyx 中编写了一份文档(具体来说是一份数值分析课程的摘要),在尝试使用 Python 代码的 minted 环境编译我的文档时出现以下错误:
FancyVerb 错误:\end{minted} \
此输入将被丢弃。请输入以继续。
这是 TeX 框内的代码:
\begin{minted}[linenos=true, numbersep=5pt, fontsize=\small]{python}
if expression:
Statements1
else:
Statements2
\end{minted}
我也补充一下我的序言:
\usepackage{changepage}
\usepackage{multicol}
\usepackage{newtxmath}
\usepackage[bottom]{footmisc}
\usepackage{marginnote}
\usepackage{algorithm,algpseudocode}
\usepackage{color}
\definecolor{scalakeyword}{rgb}{0.16,0.07,0.5}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{aqua}{rgb}{0.9,0.96,0.999}
\definecolor{scalatype}{rgb}{0.2,0.3,0.2}
\definecolor{teal}{rgb}{0,0.6,0}
\definecolor{pythonkeyword}{rgb}{0,0.6,0}
\definecolor{operatorcolor}{rgb}{141,38,165}
\definecolor{newcolor}{RGB}{0.9,0.96,0.999}
\usepackage{listingsutf8}
\usepackage{minted}
\usepackage{shellesc}
\setminted{
bgcolor=aqua,
}
\setminted{tabsize=4}
\setminted{linenos=true}
\usepackage{ifthenx}
\usepackage{xifthen}
\usepackage{fvextra}
我“咨询”了 chatgpt 有关此错误的问题,但它无法理解出了什么问题。也许你能帮助我?
我在这里添加了我的文档的乳胶代码(仅提示错误的部分):
#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
\usepackage{changepage}
\usepackage{multicol}
\usepackage{newtxmath}
\usepackage[bottom]{footmisc}
\usepackage{marginnote}
\usepackage{algorithm,algpseudocode}
\usepackage{color}
\definecolor{scalakeyword}{rgb}{0.16,0.07,0.5}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{aqua}{rgb}{0.9,0.96,0.999}
\definecolor{scalatype}{rgb}{0.2,0.3,0.2}
\definecolor{teal}{rgb}{0,0.6,0}
\definecolor{pythonkeyword}{rgb}{0,0.6,0}
\definecolor{operatorcolor}{rgb}{141,38,165}
\definecolor{newcolor}{RGB}{0.9,0.96,0.999}
\usepackage{listingsutf8}
\usepackage{minted}
\usepackage{shellesc}
\setminted{
bgcolor=aqua,
}
\setminted{tabsize=4}
\setminted{linenos=true}
\usepackage{ifthenx}
\usepackage{xifthen}
\usepackage{fvextra}
\end_preamble
\use_default_options true
\begin_modules
eqs-within-sections
figs-within-sections
tabs-within-sections
\end_modules
\maintain_unincluded_children false
\language hebrew
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "Calibri"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts true
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement H
\paperfontsize 10
\spacing onehalf
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder true
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize default
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine natbib
\cite_engine_type authoryear
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 1cm
\topmargin 3cm
\rightmargin 1cm
\bottommargin 2cm
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle fancy
\listings_params "language=Python,basicstyle={\ttfamily},keywordstyle={\bfseries\color[rgb]{0,0.5,0}},stringstyle={\color{red}},commentstyle={\color{gray}},morekeywords={False, class, finally, is, return, None, continue, for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except, in, raise, and, or, not, is, is not, in, not in},backgroundcolor={\color{aqua}}"
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Standard
\begin_inset ERT
status open
\begin_layout Plain Layout
...
...
...
...
...
...
\begin_layout Subsection
תזכורת: פייתון
\end_layout
\begin_layout Standard
משום שבקורס זה האלגוריתמים נכתבים בשפת פייתון, נזכיר מספר פונקציות ועקרונות
חשובים של השפה:
\series bold
\begin_inset Newline newline
\end_inset
\begin_inset Newline newline
\end_inset
בקרת זרימה.
\series default
ניתן לבצע בקרה על התקדמות הקוד באמצעות משפטי תנאי, הנכתבים תוך שימוש בפקודות
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
ו
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
else
\lang hebrew
:
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
begin{minted}[linenos=true, numbersep=5pt, fontsize=
\backslash
small]{python}
\end_layout
\begin_layout Plain Layout
if expression:
\end_layout
\begin_layout Plain Layout
Statements1
\end_layout
\begin_layout Plain Layout
else:
\end_layout
\begin_layout Plain Layout
Statements2
\end_layout
\begin_layout Plain Layout
\backslash
end{minted}
\end_layout
\end_inset
\begin_inset Newline newline
\end_inset
הביטוי )
\lang english
expression
\lang hebrew
( מימין לפקודת
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\lang hebrew
, מתאר את התנאי שצריך להתקיים, כדי שהתוכנה
\begin_inset Quotes eld
\end_inset
תיכנס
\begin_inset Quotes erd
\end_inset
לתוך הבלוק הראשון )המוגדר באמצעות ההזחה.
שורה
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
2
\numeric off
( ותבצע את הפעולות שכתובות בו )
\lang english
Statements
\lang hebrew
(.
כלומר, הכניסה לתוך הבלוק הראשון תתבצע רק אם הערך הבוליאני של הביטוי מימין
לפקודת
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\lang hebrew
יהיה
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
True
\lang hebrew
.
לעומת זאת, כאשר הערך הבוליאני
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
הזה
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
הינו
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
False
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
,
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
התוכנה לא תבצע את הפעולות שכתובות מתחתיו, ותעבור לבלוק השני )שורה
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
4
\numeric off
(.
\begin_inset Newline newline
\end_inset
\begin_inset Newline newline
\end_inset
חשוב להדגיש ששני התנאים המוגדרים עבור פקודות
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\lang hebrew
ו
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
else
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
הם
\series bold
משלימים
\series default
.
כלומר, אם התנאי שמימין לפקודת
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series bold
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
מתקיים
\series default
, אז התנאי שמוגדר עבור פקודת
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
else
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
בהכרח
\series bold
לא מתקיים
\series default
, ולהפך: אם התנאי שמימין לפקודת
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series bold
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
לא מתקיים
\series default
, אז התנאי שמוגדר עבור פקודת
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
else
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
בהכרח
\series bold
מתקיים
\series default
.
\begin_inset Newline newline
\end_inset
\begin_inset Newline newline
\end_inset
ניתן לקונן מספר פקודות
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
\lang english
if
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\lang hebrew
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
אחת בתוך השנייה כאשר רוצים לבצע בקרה באמצעות מספר תנאים:
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
begin{minted}[linenos=true, numbersep=5pt, fontsize=
\backslash
small]{python}
\end_layout
\begin_layout Plain Layout
if grade >= 90:
\end_layout
\begin_layout Plain Layout
print(
\begin_inset Quotes eld
\end_inset
A
\begin_inset Quotes erd
\end_inset
)
\end_layout
\begin_layout Plain Layout
else:
\end_layout
\begin_layout Plain Layout
if grade >= 80:
\end_layout
\begin_layout Plain Layout
print(
\begin_inset Quotes eld
\end_inset
B
\begin_inset Quotes erd
\end_inset
)
\end_layout
\begin_layout Plain Layout
else:
\end_layout
\begin_layout Plain Layout
if grade >= 70:
\end_layout
\begin_layout Plain Layout
print(
\begin_inset Quotes eld
\end_inset
C
\begin_inset Quotes erd
\end_inset
)
\end_layout
\begin_layout Plain Layout
else:
\end_layout
\begin_layout Plain Layout
if grade >= 60:
\end_layout
\begin_layout Plain Layout
print(
\begin_inset Quotes eld
\end_inset
D
\begin_inset Quotes erd
\end_inset
)
\end_layout
\begin_layout Plain Layout
else:
\end_layout
\begin_layout Plain Layout
print(
\begin_inset Quotes eld
\end_inset
F
\begin_inset Quotes erd
\end_inset
)
\end_layout
\begin_layout Plain Layout
\backslash
end{minted}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
restoregeometry
\end_layout
\end_inset
\end_layout
\end_body
\end_document
三个点代表 Latex 代码中与错误无关的部分(有关课程的文本)。
答案1
问题是由于某些材料位于同一行而引起的\end{minted}
,例如,
\begin{minted}
Some code
\end{minted}\\
通过消除\\
错误就解决了。