![更改 optidef 包中的语言文本变量](https://linux22.com/image/389123/%E6%9B%B4%E6%94%B9%20optidef%20%E5%8C%85%E4%B8%AD%E7%9A%84%E8%AF%AD%E8%A8%80%E6%96%87%E6%9C%AC%E5%8F%98%E9%87%8F.png)
我如何更改 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}