amsmath:如何制作带有或不带有标签的内联标签?

amsmath:如何制作带有或不带有标签的内联标签?

我有一个后续问题@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代替。l3keyspgfkeys\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}

相关内容