我想在任何地方手动使用习惯的方程编号和标签;例如在数组中。
使用该命令
\newcommand{\tagx}[1][]{\refstepcounter{equation}(\theequation)\label{#1}}
我可以创建自定义标签\tagx
或\tagx[eq:bar]
并像往常一样引用它们\eqref{eq:bar}
。
但是在具有自己的图形的标签中
\newcommand\mytag[2][]{\begingroup \renewcommand{\theequation}{#2}% ändern (\theequation)\label{#1} % ausschreiben \endgroup }
仍然有效\mytag[eq:bar1]{***}
,但不能引用\eqref{eq:bar1}
。
我能做些什么?
\documentclass[12pt]{scrreprt}
\usepackage{amsmath, amsfonts, amssymb}
\newcommand{\tagx}[1][]{\refstepcounter{equation}(\theequation)\label{#1}}
\newcommand\mytag[2][]{\begingroup
\renewcommand{\theequation}{#2}% ändern
(\theequation)\label{#1} % ausschreiben
\endgroup
}
% \renewcommand{\theequation}{\refstepcounter{equation}(\theequation)}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\chapter{First Chapter}
An equation for counting:
\begin{equation}
a+b=c\label{eq:foo1}
\end{equation}
The tag of the equation is \eqref{eq:foo1}.
\section{Putting a tag in the text}
A normal tag in the text \tagx[eq:bar0] and an own tag \mytag[eq:bar1]{***} is showing correct.
The referencing of the normal tag in the text \eqref{eq:bar0} is correct; but the own tag \eqref{eq:bar1} is wrong - here should be "(***)".
\bigskip
Another equation:
\begin{equation}
1+1=2\label{eq:foo2}
\end{equation}
The tag of the equation is \eqref{eq:foo2}.
\end{document}
答案1
您的\mytag
命令未设置\@currentlabel
。
\makeatletter
\newcommand\mytag[2][]{%
\def\@currentlabel{#2}%
(#2)\label{#1}% ausschreiben
}
\makeatother
我不确定为什么“标签”参数是可选的:你需要是吗?
\documentclass[12pt]{scrreprt}
\usepackage{amsmath, amsfonts, amssymb}
\usepackage[colorlinks=true]{hyperref}
\newcommand{\tagx}[1][]{\refstepcounter{equation}(\theequation)\label{#1}}
\makeatletter
\newcommand\mytag[2][]{%
\def\@currentlabel{#2}%
(#2)\label{#1} % ausschreiben
}
\makeatother
% \renewcommand{\theequation}{\refstepcounter{equation}(\theequation)}
\begin{document}
\chapter{First Chapter}
An equation for counting:
\begin{equation}
a+b=c\label{eq:foo1}
\end{equation}
The tag of the equation is \eqref{eq:foo1}.
\section{Putting a tag in the text}
A normal tag in the text \tagx[eq:bar0] and an own tag \mytag[eq:bar1]{***} is showing correct.
The referencing of the normal tag in the text \eqref{eq:bar0} is correct; but the own tag \eqref{eq:bar1} is wrong - here should be "(***)".
\bigskip
Another equation:
\begin{equation}
1+1=2\label{eq:foo2}
\end{equation}
The tag of the equation is \eqref{eq:foo2}.
\end{document}
我会以不同的方式来实现它:标签应该是强制性的,而个人标签是可选的。
\documentclass[12pt]{scrreprt}
\usepackage{amsmath, amsfonts, amssymb, xparse}
\usepackage[colorlinks=true]{hyperref}
\makeatletter
\NewDocumentCommand{\tagx}{om}{%
\IfNoValueTF{#1}
{% normal equation number
\refstepcounter{equation}(\theequation)\label{#2}%
}
{% personal tag
(#1)\def\@currentlabel{#1}\label{#2}%
}%
}
\makeatother
\begin{document}
\chapter{First Chapter}
An equation for counting:
\begin{equation}
a+b=c\label{eq:foo1}
\end{equation}
The tag of the equation is \eqref{eq:foo1}.
\section{Putting a tag in the text}
A normal tag in the text \tagx{eq:bar0} and an own
tag \tagx[***]{eq:bar1} is showing correct.
The referencing of the normal tag in the text \eqref{eq:bar0}
is correct; the own tag \eqref{eq:bar1} is correct as well.
Another equation:
\begin{equation}
1+1=2\label{eq:foo2}
\end{equation}
The tag of the equation is \eqref{eq:foo2}.
\end{document}
答案2
我想你想要类似的东西
\documentclass[12pt]{scrreprt}
\usepackage{amsmath, amsfonts, amssymb}
\newcommand{\tagx}[1]{\refstepcounter{equation}(\theequation)\label{#1}}
\makeatletter
\newcommand\mytag[2]{{%
#2%
\def\@currentlabel{#2}%
\label{#1}%
}}
\makeatother
% \renewcommand{\theequation}{\refstepcounter{equation}(\theequation)}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\chapter{First Chapter}
An equation for counting:
\begin{equation}
a+b=c\label{eq:foo1}
\end{equation}
The tag of the equation is \eqref{eq:foo1}.
\section{Putting a tag in the text}
A normal tag in the text \tagx{eq:bar0} and an own tag \mytag{eq:bar1}{***} is showing correct.
The referencing of the normal tag in the text \eqref{eq:bar0} is correct; but the own tag \eqref{eq:bar1} is wrong - here should be "(***)".
\bigskip
Another equation:
\begin{equation}
1+1=2\label{eq:foo2}
\end{equation}
The tag of the equation is \eqref{eq:foo2}.
\end{document}