
Ich versuche, ein Makro zu schreiben, das Informationen aus einem Etikett extrahiert und formatiert.
Ich bekomme die Nachrichten
! Argument of \@firstoftwo has an extra }.
<inserted text>
\par
l.84 ... is text that refers to \fullcref{sec:foo}
. \\
? x
Aus
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{xparse}
\newcommand \pagecref [1]
{
\fullcref{#1} on \cpageref{#1}
}
\newcommand \Pagecref [1]
{
\Fullcref{#1} on \cpageref{#1}
}
\ExplSyntaxOn
% Remove when added to expl3
\cs_generate_variant:Nn \str_show:n {e}
\cs_generate_variant:Nn \tl_log:n {e}
\cs_generate_variant:Nn \tl_show:n {e}
% Render type # (description)
% \begin{equation} does not retain optional parameter in \nameref{label}
\NewDocumentCommand \fullcref {m}
{
\fullcref:nn {\cref} {#1}
}
\NewDocumentCommand \Fullcref {m}
{
\fullcref:nn {\Cref} {#1}
}
\cs_new:Npn \fullcref:nn #1 #2
{
% \str_show:e {fullcref:~#2~has~\tl_count:n {#2}~tokens}
% \str_show:e {fullcref:~#2~labels~a~\namecref{#2}}
% \tl_show:e {fullcref:~#2~has~environment~type~#1{#2}}
\bool_if:nTF
{
% \str_if_eq_p:ee {\nameref{#2}} {equation} ||
\str_if_eq_p:ee {\str_range:nnn {#2} {1} {3}} {eq:} ||
\str_if_eq_p:ee {\namecref{#2}} {}
}
{
% \str_show:n {true}
% #1 {#2} on \cpageref{#2}
true
}
{
% \str_show:n {false}
% #1 {#2} (\nameref{#2}) on \cpageref{#2}
false
}
}
\ExplSyntaxOff
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\def\definitionutorefname{Definition} % Needed for \autoref
\newtheorem{example}[theorem]{Example}
\usepackage[colorlinks,hidelinks,draft=false]{hyperref}
\usepackage{cleveref}
\usepackage[draft]{showlabels}
\begin{document}
\section{foo bear}
\label{sec:foo}
This is dummy text.
\begin{equation}
\label{eq:foo}
\end{equation}
This is text that refers to \fullcref{sec:foo}. \\
This is text that refers to \fullcref{eq:foo}. \\
This is text that refers to \fullcref{def:foo}. \\
This is text that refers to \fullcref{def:bar}. \\
This is text that refers to \pagecref{sec:foo}. \\
This is text that refers to \pagecref{eq:foo}. \\
This is text that refers to \pagecref{def:foo}. \\
This is text that refers to \pagecref{def:bar}. \\
\begin{definition}
\label{def:foo}
This is a definition without descriptive text.
\end{definition}
\Fullcref{sec:foo}. \\
\Fullcref{eq:foo}. \\
\Fullcref{def:foo}. \\
\Fullcref{def:bar}. \\
\Pagecref{sec:foo}. \\
\Pagecref{eq:foo}. \\
\Pagecref{def:foo}. \\
\Pagecref{def:bar}. \\
\begin{definition}[dummy definition]
\label{def:bar}
This is a definition with descriptive text.
\end{definition}
\end{document}
Zweiter Versuch
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{xparse}
\newcommand \pagecref [1]
{%
\fullcref{#1} on \cpageref{#1}
}
\newcommand \Pagecref [1]
{%
\Fullcref{#1} on \cpageref{#1}
}
\ExplSyntaxOn
% Remove when added to expl3
\cs_generate_variant:Nn \str_if_eq_p:nn {xx}
\cs_generate_variant:Nn \str_show:n {e}
\cs_generate_variant:Nn \tl_log:n {e}
\cs_generate_variant:Nn \tl_show:n {e}
% Render type # (description)
% \begin{equation} does not retain optional parameter in \nameref{label}
\NewDocumentCommand \fullcref {m}
{%
\fullcref:nn {\cref} {#1}
}
\NewDocumentCommand \Fullcref {m}
{%
\fullcref:nn {\Cref} {#1}
}
\cs_new:Npn \fullcref:nn #1 #2
{
% \str_show:e {fullcref:~#2~has~\clist_count:n {#2}~labels}
% \str_show:e {fullcref:~#2~has~\tl_count:n {#2}~tokens}
% \str_show:e {fullcref:~#2~labels~a~\namecref{#2}}
% \tl_show:e {fullcref:~#2~has~environment~type~#1{#2}}
\bool_if:nTF
{
% \str_if_eq_p:ee {\nameref{#2}} {equation} ||
\str_if_eq_p:xx {\str_range:nnn {#2} {1} {3}} {eq:} ||
\str_if_eq_p:xx {\nameref{#2}} {}
}
{
% \str_show:n {true}
% #1 {#2} on \cpageref{#2}
true
}
{
% \str_show:n {false}
% #1 {#2} (\nameref{#2}) on \cpageref{#2}
false
}
}
\ExplSyntaxOff
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\def\definitionutorefname{Definition} % Needed for \autoref
\newtheorem{example}[theorem]{Example}
\usepackage[colorlinks,hidelinks,draft=false]{hyperref}
\usepackage{cleveref}
\usepackage[draft]{showlabels}
\begin{document}
\section{foo bear}
\label{sec:foo}
This is dummy text.
\begin{equation}
\label{eq:foo}
\end{equation}
This is text that refers to \fullcref{sec:foo}. \\
This is text that refers to \fullcref{eq:foo}. \\
This is text that refers to \fullcref{def:foo}. \\
This is text that refers to \fullcref{def:bar}. \\
This is text that refers to \pagecref{sec:foo}. \\
This is text that refers to \pagecref{eq:foo}. \\
This is text that refers to \pagecref{def:foo}. \\
This is text that refers to \pagecref{def:bar}. \\
\begin{definition}
\label{def:foo}
This is a definition without descriptive text.
\end{definition}
\Fullcref{sec:foo}. \\
\Fullcref{eq:foo}. \\
\Fullcref{def:foo}. \\
\Fullcref{def:bar}. \\
\Pagecref{sec:foo}. \\
\Pagecref{eq:foo}. \\
\Pagecref{def:foo}. \\
\Pagecref{def:bar}. \\
\begin{definition}[dummy definition]
\label{def:bar}
This is a definition with descriptive text.
\end{definition}
\end{document}
bekommt
! Missing number, treated as zero.
<to be read again>
\cs_set_nopar:Npx
l.86 ... is text that refers to \fullcref{sec:foo}
. \\
Ausführen dieser Tests mit den Paketen crossreftools und zref
\begin{document}
\section{foo bear}
\label{sec:foo}
This is dummy text.
\begin{equation}
\label{eq:foo}
\end{equation}
\begin{definition}[text for baz]
\label{def:baz}
This is anotehr definition with descriptive text.
\end{definition}
\crtlistoflabels
{\textbackslash}crtcrefcounter\{sec:foo\} = \crtcrefcounter{sec:foo}
{\textbackslash}crtcrefnamebylabel \{sec:foo\} = \crtcrefnamebylabel{sec:foo}
{\textbackslash}crtcrefresult\{sec:foo\} = \crtcrefresult{sec:foo}
{\textbackslash}crtcrefresult\{sec:foo\} = \crtcrefresult{sec:foo}
counter=\zref@extractdefault {sec:foo} {counter} {error}
envname=\zref@extractdefault {sec:foo} {envname} {error}
{\textbackslash}ztitleref \{sec:foo\} = \ztitleref {sec:foo}
{\textbackslash}crtcrefcounter\{def:baz\} = \crtcrefcounter{def:baz}
{\textbackslash}crtcrefnamebylabel \{def:baz\} = \crtcrefnamebylabel{def:bazi}
{\textbackslash}crtcrefresult\{def:baz\} = \crtcrefresult{def:baz}
{\textbackslash}crtcrefresult\{def:baz\} = \crtcrefresult{def:baz}
counter=\zref@extractdefault {def:baz} {counter} {error}
envname=\zref@extractdefault {def:baz} {envname} {error}
{\textbackslash}ztitleref \{def:baz\} = \ztitleref {def:baz}
\makeatother
Ich bekomme
\crtcrefcounter{sec:foo} = section
\crtcrefnamebylabel {sec:foo} = section
\crtcrefresult{sec:foo} =
\crtcrefresult{sec:foo} =
counter=error
envname=error
\ztitleref {sec:foo} = ??
\crtcrefcounter{def:baz} = theorem
\crtcrefnamebylabel {def:baz} = UNDEFINED LABEL
\crtcrefresult{def:baz} = 1
\crtcrefresult{def:baz} = 1
counter=error
envname=error
\ztitleref {def:baz} = ??
Es scheint also, dass cleveref von keinem der Pakete vollständig unterstützt wird. Die Ausgabe von \crtrefcounter ist für meine unmittelbaren Zwecke gut genug, aber ich habe noch kein funktionierendes Äquivalent zu \refname in crossreftools oder zref gefunden.