当默认 \crefrangelabelformat 没有括号时,引用示例范围时获得 (1)-(3) 样式

当默认 \crefrangelabelformat 没有括号时,引用示例范围时获得 (1)-(3) 样式

我需要 \crefrangelabelformat 没有括号,这样我就可以处于“已经在括号之间”的上下文中输入 1-3,例如(对于这个问题,请参阅 1-3 和以下示例)。

但是,我不知道如何使用更常见的样式 (1)–(3) 来引用 (1–3)。

我将所有参考子示例范围的编码都包括在内,以防万一,因为我不想让任何事情扰乱它。请参阅 MWE。

    \documentclass{report}
    
    \usepackage[hidelinks]{hyperref}
    \usepackage{etoolbox}
    \usepackage{xstring}
    \usepackage{philex}
    \usepackage{cleveref}
    
        \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)”
    
    % Refer to Subexample Ranges
                
                \crefname{ExNo}{}{}
                \crefname{SubExNo}{}{}
                \crefname{SubSubExNo}{}{}
                    
                \renewcommand{\theExNo}{\arabic{ExNo}}                      % Level 1 is referred to using arabic numbering.
                \renewcommand{\theSubExNo}{\theExNo\alph{SubExNo}}      % Level 2 is referred to using a small letter.
                \renewcommand{\theSubSubExNo}{\theSubExNo\roman{SubSubExNo}}    % Level 3 is referred to using roman numbering.
            

                \creflabelformat{ExNo}{#2#1#3}
% The output of the \cref command for the main level doesn't include parentheses. I could write (#2#1#3) but then I wouldn't know how to get an output without parentheses.

                \creflabelformat{SubExNo}{#2#1#3}
                \creflabelformat{SubSubExNo}{#2#1#3}        

        
                \crefrangelabelformat{ExNo}{#3#1#4–#5#2#6}
% Here too I could write \crefrangelabelformat{ExNo}{(#3#1#4)–(#5#2#6)} but then I wouldn't know how to type 1–3 without parentheses.

            
                \crefrangelabelformat{SubExNo}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}        
            
                \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) : it adds parentheses to \cref.
                \newcommand\prefrange[2]{(\crefrange{#1}{#2})}      % \prefrange = (\crefrange) : it adds parentheses to \crefrange.
                                                                    % PROBLEM : I want (2)–(6) style, not (2–6).
                
            
                \newcommand{\crefrangeconjunction}{–} % Use en dash instead of "to" in ranges.
                
    \begin{document}
    
    \lb{ex1}{\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.'}}}
                
    \vspace{6pt}    
    
    \lb{ex2}{\textbf{Example 2.}}
    
    \vspace{6pt}    
    
    \lb{ex3}{\textbf{Example 3.}}
    
    \vspace{6pt}    
    
    \noindent As seen in \prefrange{manner}{object} (cf. \crefrange{manner}{object}), ranges work well \textit{with and without parentheses}.
    
    \vspace{6pt}    
    
    \bfseries
    However :
    
    I want to get (1)–(3), but I can only get \crefrange{ex1}{ex3} or \prefrange{ex1}{ex3}.
    
    
    \end{document}

在此处输入图片描述

答案1

目前我能想到的只有:

\newcommand{\prange}[2]{(\cref{#1})--(\cref{#2})}

但它不支持页码。

本着同样的精神,我在这里更新了我的帖子:

https://tex.stackexchange.com/a/637115/262813

相关内容