我正在使用mathpartir
包,我有一些代码(由 LyX 生成)将环境(我将其称为lines
)放在中,并且只要其中有超过两行(以 分隔) \inferrule*
,它似乎就会出现问题。我尝试了几种方法,但只要环境中有分隔两行,就无法编译任何东西。pdflatex
\\
\\
lines
下面的代码正是我在Pastebin上上传的代码:http://pastebin.com/yBfm1zQ0
\documentclass{article}
\usepackage{mathpartir}
\begin{document}
\newcommand{\testa}{
This is the intended use:
\begin{mathpar}
\inferrule*{
1\\
2
}{
3
}
\end{mathpar}
}
\newcommand{\testb}{
% LaTeX Error: \begin{mathpar} on input line 68 ended by \end{lines}. [\testb]
But (because the code is generated), I have an environment in the rule:
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{
\begin{lines}
1\\
2
\end{lines}
}{
3
}
\end{mathpar}
}
\newcommand{\testc}{
If \textbackslash\textbackslash is renamed \textbackslash{}plop, it works (or well, the output isn't what is expected but I know how to fix it and at least it compiles):
\newcommand{\plop}{\\\relax}
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{
\begin{lines}
1\plop
2
\end{lines}
}{
3
}
\end{mathpar}
}
\newcommand{\testd}{
% LaTeX Error: \begin{mathpar} on input line 70 ended by \end{lines}. [\testd]
And it's not the \textbackslash{}relax that fixes it:
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{
\begin{lines}
1\\\relax
2
\end{lines}
}{
3
}
\end{mathpar}
}
% Line 66
%\testa
\testb
%\testc
%\testd
\end{document}
预先感谢您的帮助。
答案1
环境是一个组,所以你的代码就像
{#1\\#2}
这是行不通的,你可以定义一个非环境来破坏分组,所以定义更像是
{}#1\\#2{}
有两个虚假的空组,而不是一个围绕整个事物的组。
\documentclass{article}
\usepackage{mathpartir}
\begin{document}
\newcommand{\testa}{
This is the intended use:
\begin{mathpar}
\inferrule*{
1\\
2
}{
3
}
\end{mathpar}
}
\makeatletter
\newenvironment{lines}{\endgroup}{\begingroup\def\@currenvir{lines}}
\makeatother
\newcommand{\testb}{
% LaTeX Error: \begin{mathpar} on input line 68 ended by \end{lines}. [\testb]
But (because the code is generated), I have an environment in the rule:
\begin{mathpar}
\inferrule*{
\begin{lines}
1\\
2
\end{lines}
}{
3
}
\end{mathpar}
}
\newcommand{\testc}{
If \textbackslash\textbackslash is renamed \textbackslash{}plop, it works (or well, the output isn't what is expected but I know how to fix it and at least it compiles):
\newcommand{\plop}{\\\relax}
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{
\begin{lines}
1\plop
2
\end{lines}
}{
3
}
\end{mathpar}
}
\newcommand{\testd}{
% LaTeX Error: \begin{mathpar} on input line 70 ended by \end{lines}. [\testd]
And it's not the \textbackslash{}relax that fixes it:
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{
\begin{lines}
1\\\relax
2
\end{lines}
}{
3
}
\end{mathpar}
}
% Line 66
%\testa
\testb
%\testc
%\testd
\end{document}
答案2
我找到了解决办法,但我不明白 >_<
\newcommand{\teste}{
I finally found a fix. Apparently, \textbackslash{}inferrule* doesn't like having several things in its content so if you wrap everything in \{...\}, it works...
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{
{
\begin{lines}
1\\
2
\end{lines}
}
}{
3
}
\end{mathpar}
}
最奇怪的是,如果两个 { 互相接触,} 也互相接触,就会失败 >_<
\newcommand{\teste}{
I finally found a fix. Apparently, \textbackslash{}inferrule* doesn't like having several things in its content so if you wrap everything in \{...\}, it works...
\newenvironment{lines}{}{}
\begin{mathpar}
\inferrule*{{
\begin{lines}
1\\
2
\end{lines}
}}{
3
}
\end{mathpar}
}