Das Folgende ist eine reine LaTeX3 Implementierung, die das `l3keys` Modul verwendet. Falls du Erläuterungen benötigst, frag einfach. Anstelle von `l3keys` könnte selbstverständlich auch `pgfkeys` verwendet werden, das optionale Argument müsste einfach an `\pgfkeys` statt `\keys_set:nn` übergeben werden und statt `\keys_define:nn` würde `\pgfkeys` auch zum Definieren verwendet.
\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}
**Ergänzung:** eine bis auf `xparse` LaTeX3 freie Implementierung:
\documentclass[12pt]{scrreprt}
\usepackage[]{amsmath}
\usepackage{xparse}
\usepackage{pgfkeys}
\makeatletter
\newcommand*\cistagx@label{}
\newcommand*\cistagx@name{}
\pgfkeys
{%
/cis/tagx/.cd
,label/.store in=\cistagx@label
,name/.store in=\cistagx@name
}
\NewDocumentCommand \tagx { O{} }
{%
\begingroup
\pgfkeys{/cis/tagx/.cd,#1}
\ifx\cistagx@name\@empty
\refstepcounter{equation}%
(\theequation)%
\ifx\cistagx@label\@empty
\else
\expandafter\label\expandafter{\cistagx@label}%
\fi
\else
(\cistagx@name)%
\ifx\cistagx@label\@empty
\else
\let\@currentlabel\cistagx@name
\expandafter\label\expandafter{\cistagx@label}%
\fi
\fi
\endgroup
}
\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}
**Ergänzung 2:** Eine Version, die zwar LaTeX3 verwendet, nicht aber `l3keys` (wieso das bevorzugt werden sollte, ist mir allerdings schleierhaft):
\documentclass[12pt]{scrreprt}
\usepackage[]{amsmath}
\usepackage{xparse} % lädt auch `expl3`
\usepackage{pgfkeys}
\makeatletter
\ExplSyntaxOn
\tl_new:N \l__cis_tagx_label_tl
\tl_new:N \l__cis_tagx_name_tl
\pgfkeys
{%
/cis/tagx/.cd
% we have to use `.store~in` instead of `.store in` as the spaces are
% ignored in expl3 and `~` is a space here.
,label/.store~in=\l__cis_tagx_label_tl
,name/.store~in=\l__cis_tagx_name_tl
}
\NewDocumentCommand \tagx { O{} }
{%
\group_begin:
\pgfkeys{/cis/tagx/.cd,#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:Nx \@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}