我如何更改 optidef 包的语言。
具体来说,我想重新定义“最小化”和“受制于”文本变量:
\documentclass{report}
\usepackage{amsmath, optidef}
\newcommand{\norm}[1]{\lVert#1\rVert_2}
\begin{document}
\begin{mini!}[short]
{x}{ \norm{f(x)}^2 \label{eq:optProb}}{}{}
\addConstraint{\alpha + (\beta*\gamma)}{ \geq 0,\label{eq:constraint1}}
\addConstraint{\beta}{\geq 0.\label{eq:constraint2}}
\end{mini!}
\end{document}
答案1
免责声明:这感觉像是改变事物的错误方式......
这些单词subject~to
在包 .sty 文件中是硬编码的,但您可以重新定义\bodySubjectToDefinition
宏。在下面的示例中,将更改为xxx~subject~to
您喜欢的任何语言。
环境也一样mini!
。zzz~minimize
在下面的示例中进行更改。
\documentclass{report}
\usepackage{amsmath, optidef}
\newcommand{\norm}[1]{\lVert#1\rVert_2}
\renewcommand{\localOptimalVariable}{sfds}
\renewcommand{\bodySubjectToDefinition}{
%## If the short version of "subject to", i.e. "s.t.", should be used the command \bodySubjectTo should be modified
\ifthenelse{\equal{\localProblemFormat}{s}}
{%%
\global\def\bodySubjectTo{\mathmakebox[\widthof{$\underset{\displaystyle \phantom{\localOptimalVariable}}{\mathrm{\localProblemType}}$}][c]{\mathmakebox[\widthof{$\mathrm{\localProblemType}$}][l]{\mathrm{\kern 0.1em s.t.}}}}
}{%%
\global\def\bodySubjectTo{\mathmakebox[\widthof{$\underset{\displaystyle \phantom{\localOptimalVariable}}{\mathrm{\,sucbject~to}}$}][c]{\mathmakebox[\widthof{$\mathrm{\localProblemType}$}][l]{\mathrm{xxx~subject~to}}}}
}%%
%
}
% Multiple reference
\DeclareDocumentEnvironment{mini!}{D||{\defaultProblemFormat} O{\defaultConstraintFormat} D<>{} m m m m}
{\ifthenelse{\equal{#1}{s}}
% Short version problem
{\setFormatShort{min}{#2} \BaseMiniExclam{#2}{#4}{#5}{#6}{#7}{min}{#3}}
% Long version problem
{\setFormatLong{minimize}{#2} \BaseMiniExclam{#2}{#4}{#5}{#6}{#7}{zzz~minimize}{#3}}
}{\endBaseMiniExclam\toggletrue{bodyCon}}
\begin{document}
\begin{mini!}[short]
{x}{ \norm{f(x)}^2 \label{eq:optProb}}{}{}
\addConstraint{\alpha + (\beta*\gamma)}{ \geq 0,\label{eq:constraint1}}
\addConstraint{\beta}{\geq 0.\label{eq:constraint2}}
\end{mini!}
\end{document}