2

I use Cleveref to refer to subexamples such as "2a–c". Now I want to use crefrange to refer to 1ai–ii as well.

\documentclass[a4paper,12pt]{report}

\usepackage{philex} \usepackage{cleveref}

% Tells Cleveref to refer to a range of subexamples without repeating the number of the example.

\crefname{ExNo}{}{} \crefname{SubExNo}{}{} \renewcommand{\theExNo}{\arabic{ExNo}} \renewcommand{\theSubExNo}{\theExNo\alph{SubExNo}} \creflabelformat{SubExNo}{(#2#1#3)} \creflabelformat{ExNo}{(#2#1#3)} \crefrangelabelformat{SubExNo}{(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}

% Now I define the subsublevel : \crefname{SubSubExNo}{}{} \renewcommand{\theSubSubExNo}{\theSubExNo\roman{SubSubExNo}} \creflabelformat{SubSubExNo}{(#2#1#3)} \crefrangelabelformat{SubSubExNo}{(#3#1#4--#5#2#6)}

\begin{document}

\ex. \label{lakintpur} \a. \label{lakintpura}\a. Greg's intention was to overthrow the government. \label{intention} \b. Greg's purpose was to overthrow the government. \label{purpose} \z.\b.\label{lakintpurb}\a. Greg intended to overthrow the government. \label{intendv} \b.*Greg purposed to overthrow the government. \label{purposev}

With \crefrange{lakintpura}{lakintpurb}, I can refer to a range of subexamples, 1a–b. \par \textbf{Now I want to use crefrange to refer to 1ai–ii.}

\vspace{0.5cm}

It would also be nice to have a delimiter, since it would improve readability, especially in such examples as "2i:i-iii" (where the first i is an actual letter). Now using Philex syntax :

\lb{cool}{We would like no delimiter \phildashes{}{:} \subformat{a}{}{.} \lba{coola}{before reference to this.} \lba{coolb}{but a colon before reference to this} \lbb{coolc}{and this}}

\rf{coolb} and \rf{coolc} are cool but, now referring to \crefrange{coolb}{coolc}, I would like the result (2a:i–ii).

% Please note : as pointed out by gusbrs, crefstripprefix won't work since in i-ii, i-iii, i-iv, ii-iii and ii-iv it will skip the first "i" of the second number as being part of the prefix.

\end{document}

Example

Thank you very much.

  • 1
    For the missing format (the ?? you get), you need to create it for SubSubExNo, just like you did for ExNo and SubExNo. However, \crefstripprefix won't work to compress the range at this level because of the roman numbering. It strips everything that is common. So what you'll get there is "(2a:i-i)", because the first "i" of the end of the range is equal to that of the beginning of the range. – gusbrs Feb 16 '22 at 22:45
  • Thanks for your answer, so there is no solution ? – Vincent Krebs Feb 17 '22 at 00:38
  • 1
    Well, I didn't say that, just said that \crefstripprefix can't handle it. Besides, getting the format for SubSubExNo already grants you correct references, even if not compressed how you want. – gusbrs Feb 17 '22 at 01:23
  • @gusbrs I'm not sure what the code lines should be, I don't understand those "#" things, I just copied it from another post. – Vincent Krebs Feb 17 '22 at 12:18
  • 1
    If you'd like an answer that just sets the format, I can prepare it, but I'm not up for a \crefstrippreffix replacement at the moment (but perhaps someone else is). – gusbrs Feb 17 '22 at 12:25
  • 1
    That's a good exercise for you. ;-) As I had already said, I'm not up for it at the moment (which doesn't mean someone else isn't). – gusbrs Feb 17 '22 at 12:44
  • For ignoring the second level (with a point instead of a colon, though), see https://tex.stackexchange.com/a/637115/262813. – Vincent Krebs Mar 15 '22 at 02:27

3 Answers3

4

In this case you can use the xstring package to cut the prefix at the colon. The following provides a macro \mystriptocolon that strips the up to the (first) colon if the prefix substring is common to both items, otherwise it leaves them unchanged.

Sample output

\documentclass[a4paper,12pt]{report}

\usepackage{philex} \usepackage{xstring} \usepackage{cleveref}

% Tells Cleveref to refer to a range of subexamples without repeating % the number of the example.

\crefname{ExNo}{}{} \crefname{SubExNo}{}{} \renewcommand{\theExNo}{\arabic{ExNo}} \renewcommand{\theSubExNo}{\theExNo\alph{SubExNo}} \creflabelformat{SubExNo}{(#2#1#3)} \creflabelformat{ExNo}{(#2#1#3)} \crefrangelabelformat{SubExNo}{(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}

% Now I define the subsublevel : \crefname{SubSubExNo}{}{} \renewcommand{\theSubSubExNo}{\theSubExNo\roman{SubSubExNo}} \creflabelformat{SubSubExNo}{(#2#1#3)} \newcommand{\mystriptocolon}[2]{\StrCut{#1}{:}{\myonea}{\myoneb}% \StrCut{#2}{:}{\mytwoa}{\mytwob}% \IfStrEq{\myonea}{\mytwoa}{\mytwob}{#2}} \crefrangelabelformat{SubSubExNo}{(#3#1#4--#5\mystriptocolon{#1}{#2}#6)}

\begin{document}

\ex. \label{lakintpur} \a. \label{lakintpura}\a. Greg's intention was to overthrow the government. \label{intention} \b. Greg's purpose was to overthrow the government. \label{purpose} \z.\b.\label{lakintpurb}\a. Greg intended to overthrow the government. \label{intendv} \b.*Greg purposed to overthrow the government. \label{purposev}

With \crefrange{lakintpura}{lakintpurb}, I can refer to a range of subexamples, 1a--b.

\paragraph{Now I want to use crefrange to refer to 1ai–ii.}

It would also be nice to have a delimiter, since it would improve readability, especially in such examples as 2i:i--iii'' (where the firsti'' is an actual letter). Now using Philex syntax :

\lb{cool}{We would like no delimiter \phildashes{}{:} \subformat{a}{}{.} \lba{coola}{before reference to this.} \lba{coolb}{but a colon before reference to this} \lbb{coolc}{and this}}

\rf{coolb} and \rf{coolc} are cool and referring to \crefrange{coolb}{coolc} gives the result (2a:i--ii). Note that \crefrange{intention}{coolc} also works.

\end{document}

Andrew Swann
  • 95,762
2

When you run your document, you get a ?? for your subsubexample reference, but also a cleveref warning: "cref reference range format for label type 'SubSubExNo' undefined". And indeed, that is what is missing. Setting one up can be just like the other ones already in your document. However, the use of \crefstripprefix won't work well for the SubSubExNo level, because of its roman numbering, since it does its job by removing the common part at the start of both references in a range. To set up the format for SubSubExNo without the range compression, you can use:

\documentclass[a4paper,12pt]{report}

% Linguistic Examples \usepackage{philex}

% Tells Cleveref to refer to a range of subexamples without repeating the number of the example. \usepackage{cleveref} % Refer to Subexample Ranges \crefname{ExNo}{}{} \crefname{SubExNo}{}{} \crefname{SubSubExNo}{}{} \creflabelformat{ExNo}{(#2#1#3)} \creflabelformat{SubExNo}{(#2#1#3)} \creflabelformat{SubSubExNo}{(#2#1#3)} \crefrangelabelformat{SubExNo}{(#3#1#4--#5\crefstripprefix{#1}{#2}#6)} % You may prefer to use this instead, for symmetry with SubSubExNo. % \crefrangelabelformat{SubExNo}{(#3#1#4--#5#2#6)} % \crefstripprefix won't work well here because of the roman numbering. \crefrangelabelformat{SubSubExNo}{(#3#1#4--#5#2#6)}

\begin{document}

\ex. \label{lakintpur} \a. \label{lakintpura}\a. Greg's intention was to overthrow the government. \label{intention} \b. Greg's purpose was to overthrow the government. \label{purpose} \z.\b.\label{lakintpurb}\a. Greg intended to overthrow the government. \label{intendv} \b.*Greg purposed to overthrow the government. \label{purposev}

With \crefrange{lakintpura}{lakintpurb}, I can refer to a range of subexamples, 1a–b.

\textbf{Now I want to use crefrange to refer to 1ai–ii.}

\vspace{0.5cm}

It would also be nice to have a delimiter, since it would improve readability, especially in such examples as "2i:i-iii" (where the first i is an actual letter). Now using Philex syntax :

\lb{cool}{We would like no delimiter \phildashes{}{:} \subformat{a}{}{.} \lba{coola}{before reference to this.} \lba{coolb}{but a colon before reference to this} \lbb{coolc}{and this}}

\rf{coolb} and \rf{coolc} are cool but, now referring to \crefrange{coolb}{coolc}, I want the result (2a:i–ii) with brackets and without the `?? bug.'

\end{document}

gusbrs
  • 13,740
  • Thank you very much ! – Vincent Krebs Feb 17 '22 at 12:48
  • "We"? C'mon, I had only commented with some helpful hints. And I only added an answer in these terms because you entreated me to do so in the comments. I had told you I was not up for a \crefstripprefix replacement, and I'm not... – gusbrs Feb 17 '22 at 12:52
  • Well I didn't include @gusbrs and I said thank you, it seems to me. So thanks again, and I'm just wondering, for other people to maybe help. – Vincent Krebs Feb 17 '22 at 13:16
  • You say that after you edited/deleted the comment that was there. I suppose you're trying to look good in the picture by so doing. You're new, so I won't be harsh. But, a hint, it doesn't work. – gusbrs Feb 17 '22 at 13:18
  • After "thank you", yes I originally added stuff, then I thought "it's ok, I'll leave him alone". Oh maybe you answered the first version, before edition. Sorry then. But again, it was addressed to everyone, not you in particular (although the "thanks" was addressed to you specifically). You think I edited after your answer but that was before I read your answer, because I thought my idea wouldn't work anyway. So no problem. – Vincent Krebs Feb 17 '22 at 13:19
  • Btw I won't edit and then say "what ? never wrote that" because I don't do that, and it's just stupid ;) But I see what you mean. – Vincent Krebs Feb 17 '22 at 13:25
0

Now mentioning pages... (remark: here the colon has been replaced by a dot)

    \documentclass{report}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage{cleveref}

\usepackage{philex} % Includes linguex and cgloss4e \AtEndPreamble{
\phildashes{}{.} % Adds a dot between levels 2 and 3 in references. Nothing between levels 1 and 2. \subformat{a}{}{.} % Level 2 is of the form “a.” \subsubformat{i}{(}{)}} % Level 3 is of the form “(i)”

\crefname{ExNo}{}{} \crefname{SubExNo}{}{} \crefname{SubSubExNo}{}{}

\renewcommand{\theExNo}{\arabic{ExNo}} % Level 1 = number \renewcommand{\theSubExNo}{\theExNo\alph{SubExNo}} % Level 2 = small letter \renewcommand{\theSubSubExNo}{\theSubExNo\roman{SubSubExNo}} % Level 3 = small roman

\creflabelformat{ExNo}{#2#1#3} % No parentheses. \creflabelformat{SubExNo}{#2#1#3} \creflabelformat{SubSubExNo}{#2#1#3}

\crefrangelabelformat{SubExNo}{#3#1#4--#5\crefstripprefix{#1}{#2}#6} % No parentheses.

\newcommand{\mystriptocolon}[2]{\StrCut{#1}{.}{\myonea}{\myoneb}% \StrCut{#2}{.}{\mytwoa}{\mytwob}% \IfStrEq{\myonea}{\mytwoa}{\mytwob}{#2}} \crefrangelabelformat{SubSubExNo}{#3#1#4--#5\mystriptocolon{#1}{#2}#6}

\newcommand\pref[1]{(\cref{#1})} % pref = (cref) \newcommand\prefrange[2]{(\crefrange{#1}{#2})} % prefrange = (crefrange)

\newcommand\crefpage[1]{\cref{#1}, \cpageref{#1}} % Number without parentheses, followed by page number after comma. \newcommand\prefpage[1]{\pref{#1} (\cpageref{#1})} % Number between parentheses, followed by page number between parentheses.

\newcommand\crefrangepage[2]{\crefrange{#1}{#2}, \cpageref{#1,#2}} % Range without parentheses, followed by page number after comma. \newcommand\prefrangepage[2]{\prefrange{#1}{#2} (\cpageref{#1,#2})} % Range between parentheses, followed by page number between parentheses.

\begin{document}

\lb{variation}{\textbf{Structural variation in relation with the source V} \vspace{0.3cm} \lba{coalition}{Transitive AS setup \vspace{0.2cm} \lba{coalition-n}{la formation d'une coalition par les transfuges\ the formation of a coalition by the defectors'} \vspace{0.2cm} \lbz{coalition-v}{Les transfuges formèrent une coalition.\\The defectors formed a coalition.'}}\vspace{0.4cm} \lbb{cliff}{Unaccusative AS setup \vspace{0.2cm} \lba{cliff-n}{la formation spontanée d'une falaise\ the spontaneous formation of a cliff'} \vspace{0.2cm} \lbz{cliff-v}{Une falaise se forma.\\A cliff formed.'}}\vspace{0.4cm} \lbz{result}{Non-AS- readings \vspace{0.4cm} \lba{simple-event}{\textsl{\textit{Simple event} reading} \vspace{0.2cm}\ Nous avons suivi une formation intensive.\ We attended an intensive training course.'} \vspace{0.4cm} \lbb{manner}{\textsl{\textit{Manner} reading} \vspace{0.2cm}\\ On peut comprendre ce mot en observant sa formation.\\One may understand this word by looking at its formation.'} \lbz{object}{\textsl{\textit{Object} reading} \vspace{0.2cm}\ Le soldat se retrouva face à une formation de chars ennemis.\ `The soldier found himself in front of an enemy tank formation.'}}}

\noindent ... As seen in \prefrange{manner}{object} (cf. \crefrange{manner}{object}). \ ... As seen in \prefrangepage{manner}{object} (cf. \crefrangepage{manner}{object})

\end{document}

enter image description here

Also see :

Crossreference in Ref Range [(1a-1e) to (1a-e)]

Any way to reference a particular component of a label?

Skip main counter in cross-referencing within Linguex and Cleveref