! Argument of @firstoftwo has an extra }ref not working with achemsoHyperref jumps to the wrong equation if...

Is there a math equivalent to the conditional ternary operator?

How does insurance birth control work?

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

Did Amazon pay $0 in taxes last year?

Relationship between the symmetry number of a molecule as used in rotational spectroscopy and point group

How to fix my table, centering of columns

Caulking a corner instead of taping with joint compound?

How to kill a localhost:8080

Is every open circuit a capacitor?

Make me a metasequence

How do we objectively assess if a dialogue sounds unnatural or cringy?

Practical reasons to have both a large police force and bounty hunting network?

Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?

I can't die. Who am I?

Why won't the strings command stop?

Was it really inappropriate to write a pull request for the company I interviewed with?

Why is my Contribution Detail Report (native CiviCRM Core report) not accurate?

PTIJ: Is all laundering forbidden during the 9 days?

PTIJ: Why can't I sing about soda on certain days?

Where is this quote about overcoming the impossible said in "Interstellar"?

Levi-Civita symbol: 3D matrix

Why is it "take a leak?"

Quitting employee has privileged access to critical information

Reason why dimensional travelling would be restricted



! Argument of @firstoftwo has an extra }


ref not working with achemsoHyperref jumps to the wrong equation if the equation has a tag and cleveref is usedHow to modify the label output in cleveref and varioref?including chapters in mdframed referencesMixing cleveref, vref and ref: Argument of @firstoftwo has an extra }hyperref error : ! Argument of @providesfile has an extra }zref-perpage doesn't work with theorem-like environmentsDestination with the same identifier name {xtheorem.1}hyperref error: Argument of Hy@setref@link has an extra }Error: Argument of newcommand{…} has an extra }













0















I am attempting to write macro that extracts and formats information from a label.



I get the messages



! Argument of @firstoftwo has an extra }.
<inserted text>
par
l.84 ... is text that refers to fullcref{sec:foo}
. \
? x


From



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}
defdefinitionutorefname{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}


Second attempt



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}
defdefinitionutorefname{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}


gets



! Missing number, treated as zero.
<to be read again>
cs_set_nopar:Npx
l.86 ... is text that refers to fullcref{sec:foo}
. \


Running these tests with the packages crossreftools and 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


I get



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} = ??


So it appears cleveref isn't fully supported by either package. The output from crtrefcounter is good enough for my immediate purposes, but I still haven't found a working equivalent to refname in either crossreftools or zref.










share|improve this question

























  • the ref commands are not expandable, so can't be used in edef (or an e argument)

    – David Carlisle
    Feb 27 at 22:42











  • If you want expandable ref commands, use the zref package.

    – Ulrike Fischer
    Feb 27 at 22:45






  • 1





    @Sebastiano please fix your edit you have changed the format of the error message from a correct code block to an incorrect quote so losing all the line breaks.

    – David Carlisle
    Feb 27 at 22:45











  • @DavidCarlisle I didn't know about this! I'll try to remedy the mistake.

    – Sebastiano
    Feb 27 at 22:47











  • unrelated to the error but you have spurious space in newcommand Pagecref [1] { Fullcref{#1} on cpageref{#1} } which would mean that you get double space before the reference in uses such as refers to Fullcref

    – David Carlisle
    Feb 27 at 22:47
















0















I am attempting to write macro that extracts and formats information from a label.



I get the messages



! Argument of @firstoftwo has an extra }.
<inserted text>
par
l.84 ... is text that refers to fullcref{sec:foo}
. \
? x


From



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}
defdefinitionutorefname{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}


Second attempt



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}
defdefinitionutorefname{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}


gets



! Missing number, treated as zero.
<to be read again>
cs_set_nopar:Npx
l.86 ... is text that refers to fullcref{sec:foo}
. \


Running these tests with the packages crossreftools and 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


I get



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} = ??


So it appears cleveref isn't fully supported by either package. The output from crtrefcounter is good enough for my immediate purposes, but I still haven't found a working equivalent to refname in either crossreftools or zref.










share|improve this question

























  • the ref commands are not expandable, so can't be used in edef (or an e argument)

    – David Carlisle
    Feb 27 at 22:42











  • If you want expandable ref commands, use the zref package.

    – Ulrike Fischer
    Feb 27 at 22:45






  • 1





    @Sebastiano please fix your edit you have changed the format of the error message from a correct code block to an incorrect quote so losing all the line breaks.

    – David Carlisle
    Feb 27 at 22:45











  • @DavidCarlisle I didn't know about this! I'll try to remedy the mistake.

    – Sebastiano
    Feb 27 at 22:47











  • unrelated to the error but you have spurious space in newcommand Pagecref [1] { Fullcref{#1} on cpageref{#1} } which would mean that you get double space before the reference in uses such as refers to Fullcref

    – David Carlisle
    Feb 27 at 22:47














0












0








0








I am attempting to write macro that extracts and formats information from a label.



I get the messages



! Argument of @firstoftwo has an extra }.
<inserted text>
par
l.84 ... is text that refers to fullcref{sec:foo}
. \
? x


From



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}
defdefinitionutorefname{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}


Second attempt



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}
defdefinitionutorefname{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}


gets



! Missing number, treated as zero.
<to be read again>
cs_set_nopar:Npx
l.86 ... is text that refers to fullcref{sec:foo}
. \


Running these tests with the packages crossreftools and 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


I get



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} = ??


So it appears cleveref isn't fully supported by either package. The output from crtrefcounter is good enough for my immediate purposes, but I still haven't found a working equivalent to refname in either crossreftools or zref.










share|improve this question
















I am attempting to write macro that extracts and formats information from a label.



I get the messages



! Argument of @firstoftwo has an extra }.
<inserted text>
par
l.84 ... is text that refers to fullcref{sec:foo}
. \
? x


From



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}
defdefinitionutorefname{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}


Second attempt



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}
defdefinitionutorefname{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}


gets



! Missing number, treated as zero.
<to be read again>
cs_set_nopar:Npx
l.86 ... is text that refers to fullcref{sec:foo}
. \


Running these tests with the packages crossreftools and 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


I get



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} = ??


So it appears cleveref isn't fully supported by either package. The output from crtrefcounter is good enough for my immediate purposes, but I still haven't found a working equivalent to refname in either crossreftools or zref.







hyperref expl3 cleveref zref crossreftools






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







shmuel

















asked Feb 27 at 22:37









shmuelshmuel

535212




535212













  • the ref commands are not expandable, so can't be used in edef (or an e argument)

    – David Carlisle
    Feb 27 at 22:42











  • If you want expandable ref commands, use the zref package.

    – Ulrike Fischer
    Feb 27 at 22:45






  • 1





    @Sebastiano please fix your edit you have changed the format of the error message from a correct code block to an incorrect quote so losing all the line breaks.

    – David Carlisle
    Feb 27 at 22:45











  • @DavidCarlisle I didn't know about this! I'll try to remedy the mistake.

    – Sebastiano
    Feb 27 at 22:47











  • unrelated to the error but you have spurious space in newcommand Pagecref [1] { Fullcref{#1} on cpageref{#1} } which would mean that you get double space before the reference in uses such as refers to Fullcref

    – David Carlisle
    Feb 27 at 22:47



















  • the ref commands are not expandable, so can't be used in edef (or an e argument)

    – David Carlisle
    Feb 27 at 22:42











  • If you want expandable ref commands, use the zref package.

    – Ulrike Fischer
    Feb 27 at 22:45






  • 1





    @Sebastiano please fix your edit you have changed the format of the error message from a correct code block to an incorrect quote so losing all the line breaks.

    – David Carlisle
    Feb 27 at 22:45











  • @DavidCarlisle I didn't know about this! I'll try to remedy the mistake.

    – Sebastiano
    Feb 27 at 22:47











  • unrelated to the error but you have spurious space in newcommand Pagecref [1] { Fullcref{#1} on cpageref{#1} } which would mean that you get double space before the reference in uses such as refers to Fullcref

    – David Carlisle
    Feb 27 at 22:47

















the ref commands are not expandable, so can't be used in edef (or an e argument)

– David Carlisle
Feb 27 at 22:42





the ref commands are not expandable, so can't be used in edef (or an e argument)

– David Carlisle
Feb 27 at 22:42













If you want expandable ref commands, use the zref package.

– Ulrike Fischer
Feb 27 at 22:45





If you want expandable ref commands, use the zref package.

– Ulrike Fischer
Feb 27 at 22:45




1




1





@Sebastiano please fix your edit you have changed the format of the error message from a correct code block to an incorrect quote so losing all the line breaks.

– David Carlisle
Feb 27 at 22:45





@Sebastiano please fix your edit you have changed the format of the error message from a correct code block to an incorrect quote so losing all the line breaks.

– David Carlisle
Feb 27 at 22:45













@DavidCarlisle I didn't know about this! I'll try to remedy the mistake.

– Sebastiano
Feb 27 at 22:47





@DavidCarlisle I didn't know about this! I'll try to remedy the mistake.

– Sebastiano
Feb 27 at 22:47













unrelated to the error but you have spurious space in newcommand Pagecref [1] { Fullcref{#1} on cpageref{#1} } which would mean that you get double space before the reference in uses such as refers to Fullcref

– David Carlisle
Feb 27 at 22:47





unrelated to the error but you have spurious space in newcommand Pagecref [1] { Fullcref{#1} on cpageref{#1} } which would mean that you get double space before the reference in uses such as refers to Fullcref

– David Carlisle
Feb 27 at 22:47










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477047%2fargument-of-firstoftwo-has-an-extra%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477047%2fargument-of-firstoftwo-has-an-extra%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Why does my Macbook overheat and use so much CPU and energy when on YouTube?Why do so many insist on using...

How to prevent page numbers from appearing on glossaries?How to remove a dot and a page number in the...

Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...