![在 optidef 约束中使用案例环境会导致错误消息](https://linux22.com/image/435692/%E5%9C%A8%20optidef%20%E7%BA%A6%E6%9D%9F%E4%B8%AD%E4%BD%BF%E7%94%A8%E6%A1%88%E4%BE%8B%E7%8E%AF%E5%A2%83%E4%BC%9A%E5%AF%BC%E8%87%B4%E9%94%99%E8%AF%AF%E6%B6%88%E6%81%AF.png)
我正在尝试使用该optidef
包来排版优化问题。我想cases
在其中一个约束中使用环境,但 LaTeX 一直抱怨}
我似乎找不到其他约束。这是一个 MWE:
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage[short,nocomma]{optidef}
\begin{document}
\begin{mini!}
% Variables
{x,f}
%%%%%%%%%%%%%%%%%%%%%%
% Objective function %
%%%%%%%%%%%%%%%%%%%%%%
{%
\sum_{\{i,j\} \in E} c_{\{i,j\}} x_{\{i,j\}}\label{prob:mst:obj}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem label and result %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{%
\label{prob:mst}
}{%
% left empty on purpose
}
%%%%%%%%%%%%%%%%%%%%%
% First constraint %
%%%%%%%%%%%%%%%%%%%%%
\addConstraint{%
% LHS
\sum_{(i,j) \in \delta^+(i)} f_{(i,j)} - \sum_{(j,i) \in \delta^-(i)} f_{(j,i)}
}{%
% RHS
=\,
\begin{cases}
\vert V \vert -1 & i=r\\
-1 & i\neq r
\end{cases}
\label{prob:mst:cnstr2}
}{%
% Description or quantification
\quad\forall i \in V
}
\end{mini!}
\end{document}
这是从文件中截取的片段.log
:
./mwe.tex:41: Argument of \reserved@a has an extra }.
<inserted text>
\par
l.41 \end{mini!}
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
Runaway argument?
{\def \@currenvir {cases}\edef \@currenvline {\on@line }\csuse {@begi\ETC.
./mwe.tex:41: Paragraph ended before \reserved@a was complete.
<to be read again>
\par
l.41 \end{mini!}
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
./mwe.tex:41: Missing } inserted.
<inserted text>
}
l.41 \end{mini!}
I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work.
./mwe.tex:41: Extra }, or forgotten $.
<template> }
$}\ifmeasuring@ \savefieldlength@ \fi \set@field \hfil \endtempl...
l.41 \end{mini!}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.
./mwe.tex:41: Argument of \reserved@a has an extra }.
<inserted text>
\par
l.41 \end{mini!}
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
Runaway argument?
{\def \@currenvir {cases}\edef \@currenvline {\on@line }\csuse {@begi\ETC.
./mwe.tex:41: Paragraph ended before \reserved@a was complete.
<to be read again>
\par
l.41 \end{mini!}
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
./mwe.tex:41: Missing } inserted.
<inserted text>
}
l.41 \end{mini!}
I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work.
./mwe.tex:41: Extra }, or forgotten $.
<template> }
$}\ifmeasuring@ \savefieldlength@ \fi \set@field \hfil \endtempl...
l.41 \end{mini!}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.
正如您上面看到的,生成的 PDF 看起来不错(那为什么要抱怨呢?)但我仍然想知道其他人是否遇到过同样的问题,以及现在忽略错误消息是否安全。
答案1
我只能通过运行 TeX Live 2016(其最终状态为optidef
版本 2.3)来重现该问题。
在 TL 2017 和optidef
版本 2.6 中不会出现此问题,在更高版本中也不会出现此问题。
如果您无法将 TeX 系统从 TL 2016(或 2017)升级到当前版本,则有一个解决方法:将环境包装cases
在\unexpanded
.
\unexpanded{\begin{cases}...\end{cases}}