Skip to content
Snippets Groups Projects
lref.tex 1.08 KiB
Newer Older
%! Author = lorenzo
%! Date = 08/09/22
\ExplSyntaxOn
\cs_new_eq:NN \strcompare \str_if_eq:eeTF
\ExplSyntaxOff

\newcommand{\lrefrange}[3][label]{\strcompare{label}{#1}{{\csname cref@line@name@plural\endcsname}~}{\strcompare{nolabel}{#1}{}{\GenericError{}{Error: Invalid option!}{}{}}}\hyperlink{#2}{\ref*{#2}}--\hyperlink{#3}{\ref*{#3}}}
Lorenzo Ferron's avatar
Lorenzo Ferron committed

%% Use ONLY \lref NOT \lreflst
\ExplSyntaxOn
\NewDocumentCommand{\lref}{m}
 {
  \clist_set:Nn \l_jour_command_input_clist { #1 }
  \exp_args:Nf \lreflst { \clist_use:Nn \l_jour_command_input_clist {,} }
 }
\clist_new:N \l_jour_command_input_clist
\ExplSyntaxOff
\newcommand{\lreflst}[1]{%
  \count255=0%
  \def\do##1{\advance\count255 1 \chardef\finalitem=\count255 }%
  \docsvlist{#1}%
  \ifnum\count255=1
  {\csname cref@line@name\endcsname}~%
  \else
  {\csname cref@line@name@plural\endcsname}~%
  \fi%
  \count255=0%
  \def\do##1{\advance\count255 1
    \ifnum\finalitem=1
    \else
    \ifnum\count255=\finalitem
      \space e\space%
    \else
      \ifnum\count255=1
      \else
    ,\space%
      \fi%
    \fi\fi\hyperlink{##1}{\ref*{##1}}}%
  \docsvlist{#1}}%