![amsmath:如何制作带有或不带有标签的内联标签?](https://linux22.com/image/395946/amsmath%EF%BC%9A%E5%A6%82%E4%BD%95%E5%88%B6%E4%BD%9C%E5%B8%A6%E6%9C%89%E6%88%96%E4%B8%8D%E5%B8%A6%E6%9C%89%E6%A0%87%E7%AD%BE%E7%9A%84%E5%86%85%E8%81%94%E6%A0%87%E7%AD%BE%EF%BC%9F.png)
我有一个后续问题@egregs 回答:
按照命令
\usepackage{xparse}
% \tagx[shown text, optional]{label-name}
\makeatletter
\NewDocumentCommand{\tagx}{om}{%
\IfNoValueTF{#1}
{% normal equation number
\refstepcounter{equation}(\theequation)\label{#2}%
}
{% personal tag
(#1)\def\@currentlabel{#1}\label{#2}%
}%
}
\makeatother
我必须始终设置标签名称:\tagx{label-name}
。
如果没有可选的标签名称(\tagx[eq *]{label-name}
---> (eq *)
),这将给出当前方程编号,(1.2)例如
我怎样才能选择性地制作标签(和显示的文本),例如
\tagx[name={eq ***}, label=foo]
梅威瑟:
(with LaTeX Warning: Label multiply defined.)
\documentclass[12pt]{scrreprt}
\usepackage{amsmath, amsfonts, amssymb}
\usepackage{xparse}
% \tagx[shown text, optional]{label-name}
\makeatletter
\NewDocumentCommand{\tagx}{om}{%
\IfNoValueTF{#1}
{% normal equation number
\refstepcounter{equation}(\theequation)\label{#2}%
}
{% personal tag
(#1)\def\@currentlabel{#1}\label{#2}%
}%
}
\makeatother
\usepackage[colorlinks=true]{hyperref} % for highlighting
\begin{document}
\chapter{First Chapter}
An equation for counting:
\begin{equation}
a+b=c\label{eq:bar1}
\end{equation}
\bigskip
This is an inline-tag \tagx{foo1}, it is also labeled \eqref{foo1}.
This is a personalized inline-tag \tagx[***]{foo2}, it is also labeled \eqref{foo2}.
\bigskip
This is an inline-tag \tagx{}, it is \emph{not} labeled.
This is a personalized inline-tag \tagx[***]{}, it is \emph{not} labeled.
\bigskip
An another equation:
\begin{equation}
1+1=2\label{eq:bar2}
\end{equation}
\end{document}
答案1
以下是我关于texwelt.de。
它是利用模块的纯 LaTeX3 实现。通过在代替中定义选项并使用代替来设置它们,可以非常轻松地使用l3keys
代替。l3keys
pgfkeys
\pgfkeys
\keys_define:nn
\pgfkeys
\keys_set:nn
\documentclass[12pt]{scrreprt}
\usepackage[]{amsmath}
\usepackage{xparse} % lädt auch `expl3`
\makeatletter
\ExplSyntaxOn
\keys_define:nn { cis / tagx }
{
,label .tl_set:N = \l__cis_tagx_label_tl
,name .tl_set:N = \l__cis_tagx_name_tl
}
\NewDocumentCommand \tagx { O{} }
{
\group_begin:
\keys_set:nn { cis / tagx } { #1 }
\tl_if_empty:NTF \l__cis_tagx_name_tl
{
\refstepcounter{equation}
( \theequation )
\tl_if_empty:NF \l__cis_tagx_label_tl
{ \exp_args:NV \label \l__cis_tagx_label_tl }
}
{
( \l__cis_tagx_name_tl )
\tl_if_empty:NF \l__cis_tagx_label_tl
{
\tl_set_eq:NN \@currentlabel \l__cis_tagx_name_tl
\exp_args:NV \label \l__cis_tagx_label_tl
}
}
\group_end:
}
\ExplSyntaxOff
\makeatother
\begin{document}
\chapter{First Chapter}
An equation for counting:
\begin{equation}
a+b=c\label{eq:bar1}
\end{equation}
\bigskip
This is an inline-tag \tagx[label=foo1], it is also labeled \eqref{foo1}.
This is a personalized inline-tag \tagx[name=***,label=foo2], it is also labeled \eqref{foo2}.
\bigskip
This is an inline-tag \tagx, it is \emph{not} labeled.
This is a personalized inline-tag \tagx[name=***], it is \emph{not} labeled.
\bigskip
An another equation:
\begin{equation}
1+1=2\label{eq:bar2}
\end{equation}
\end{document}