20

Legal reports in Germany often use a somewhat strange way of structuring. Instead of the usual numbers, we have

A.

(B., C. D. ...) for the first level,

I.

-- Roman numbers for the second level

1.

arabic numbers for the third level

a)

b), c), d) ... for the fourth level and

aa)

bb), cc), dd) for the fifth level.

I've implemented this in the following nearly minimal example. I'd like to have abbreviated references. If you are reading in section »B.« and there is a reference to subsection »B.II.«, it is enough to print »II.«. But if you are reading in section A., you need »B.II.«. If you are refering from B.II.3.a)cc) to something in B.II.3.a)bb), the output of \ref obviously should not be B.II.3.a)bb), but simply bb). If you are in B.II.4., the reference has to say 3.a)bb).

But if you are refering from somewhere in C.I.1., the full reference is needed to B.II.3.a)bb).

Special request: solution should word with the varioref package as well.

The jura documentclass provides this kind of reference. But I depend on KOMA-script for many reasons. So I tried to take the code from jura.dtx and adapt it, but I get a error message I don't understand, see below.

So: Can I have references which depend on the place where the \ref is in the text? Every solution welcome.


Edit to Ulrike's answer:

This code produces always a "II." at levels lower than subsection:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel, blindtext}

\setcounter{secnumdepth}{5} % fünf Ebenen



\renewcommand*{\thesection}{\Alph{section}.}
\renewcommand*{\thesubsection}{\Roman{subsection}.}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}.}
\renewcommand*{\theparagraph}{\alph{paragraph})}%)
\renewcommand*{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph})}

\usepackage{zref-user,zref-counter}
\usepackage{expl3}


\makeatletter


\zref@newprop{section}[1]{\the\c@section}
\zref@newprop{subsection}[1]{\the\c@subsection}

\zref@addprop{main}{section}
\zref@addprop{main}{subsection}

\ExplSyntaxOn

\newcommand\myref[1]{%
 \hyperref[#1]{
 \int_compare:nTF
  {
   \zref@extractdefault {#1} {section} {0} = \the\c@section
  }
  {
   %ref is from current section
   \int_compare:nTF
    {\zref@extractdefault {#1} {subsection} {0}  = 0 }
    {Was~nun?}
    {\int_to_Roman:n{\zref@extractdefault {#1} {subsection} {0}}.}
  }
  {
  %ref is from other section
  \int_to_Alph:n  {\zref@extractdefault {#1} {section} {0}}.
  \int_to_Roman:n {\zref@extractdefault {#1} {subsection} {0}}
  }}}

\ExplSyntaxOff
\makeatother
%\usepackage{xcolor}
\usepackage[]{hyperref}

\newcommand\Label[1]{\zlabel{#1}\label{#1}}

\begin{document}

\section{First}
\Label{sec:first}

I'm refering to the second section and I'd like to have a full
reference like this: \myref{sec:secondofsecond}.

\section{Second}
\Label{sec:second}

\myref{sec:secondofsecond}, \myref{sec:first}, \myref{sec:second} And lets test the
new references, see \myref{CLA:first-paragraph} or \myref{CLA:first-second.second}

\subsection{Firstofsecond}
\Label{sec:firstofsecond}

Text.

\subsection{Secondofsecond}
\Label{sec:secondofsecond}

Now down the tree:

\subsubsection{first of second.second}
\Label{CLA:first-second.second}

Just some letters. 

\paragraph{first-paragraph}
\Label{CLA:first-paragraph}

And more text. 



\end{document}

This is my earlier MWE, now kind of obsolete:

\documentclass[english, parskip=half, numbers=noendperiod]{scrartcl}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage{babel, blindtext}

\setcounter{secnumdepth}{5} % five levels

\renewcommand*{\thesection}{\Alph{section}.}
\renewcommand*{\thesubsection}{\Roman{subsection}.}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}.}
\renewcommand*{\theparagraph}{\alph{paragraph})}%)
\renewcommand*{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph})}
\renewcommand*{\paragraphformat}{\theparagraph{}\enskip}
\renewcommand*{\subparagraphformat}{%
  \thesubparagraph{}\enskip}

\makeatletter
\renewcommand{\p@subsection}{\thesection}
\renewcommand{\p@subsubsection}{\thesection\thesubsection}
\renewcommand{\p@paragraph}{\thesection\thesubsection\thesubsubsection}
\renewcommand{\p@subparagraph}{\thesection\thesubsection\thesubsubsection\theparagraph\,}
\makeatother{}

\begin{document}

\section{First}
\label{sec:first}

I'm refering to the second section and I'd like to have a full
reference like this: \ref{sec:secondofsecond}. 

\section{Second}
\label{sec:second}

\subsection{Firstofsecond}
\label{sec:firstofsecond}

Text.

\subsection{Secondofsecond}
\label{sec:secondofsecond}

But now I'm refering to »Firstofsecond« and my readers do not need the
full reference (\ref{sec:firstofsecond}), simply »I.« would be sufficient.

From here a reference to »first of second / second« should look like
this: »1.« and not \ref{sec:first-second-second}

\subsubsection{First of second / second}
\label{sec:first-second-second}

text.

\end{document}

OK, and now to the idea to recycle the code of the deprecated jura.dtx

Following the advice of jknappen, I tried to use the code of jura.dtx for exactly the behaviour I'd like to have. I changed the code to:

%\documentclass[english, parskip=half, numbers=noendperiod]{scrartcl}
\documentclass[english]{article}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage{babel, blindtext}

\setcounter{secnumdepth}{5} % fünf Ebenen



\renewcommand*{\thesection}{\Alph{section}.}
\renewcommand*{\thesubsection}{\Roman{subsection}.}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}.}
\renewcommand*{\theparagraph}{\alph{paragraph})}%)
\renewcommand*{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph})}

%% Code stolen from jura.dtx
\makeatletter{}
\newcommand*{\@greek}[1]{\ifcase#1\relax\or$\alpha$\or$\beta$\or
$\gamma$\or$\delta$\or$\varepsilon$\or$\zeta$\or$\eta$\or$\vartheta$\or
$\iota$\or$\kappa$\or$\lambda$\or$\mu$\or$\nu$\or$\xi$\or$o$\or$\pi$\or
$\rho$\or$\sigma$\or$\tau$\or$\upsilon$\or$\varphi$\or$\chi$\or$\psi$\or
$\omega$\else\@ctrerr\fi}
\newcounter{lvla}
\newcounter{lvlb}
\newcounter{lvlc}
\newcounter{lvld}
\newcounter{lvle}
\newcounter{lvlf}
\newcounter{lvlg}
\newcounter{lvlh}
\newcounter{lvli}
\newcounter{lvlj}
\newcounter{lvlk}
\newcounter{lvll}
\renewcommand*{\thelvla}{\J@Number}
\renewcommand*{\thelvlb}{\J@Number}
\renewcommand*{\thelvlc}{\J@Number}
\renewcommand*{\thelvld}{\J@Number}
\renewcommand*{\thelvle}{\J@Number}
\renewcommand*{\thelvlf}{\J@Number}
\renewcommand*{\thelvlg}{\J@Number}
\renewcommand*{\thelvlh}{\J@Number}
\renewcommand*{\thelvli}{\J@Number}
\renewcommand*{\thelvlj}{\J@Number}
\renewcommand*{\thelvlk}{\J@Number}
\renewcommand*{\thelvll}{\J@Number}

\newcounter{tiefe}\setcounter{tiefe}{1}
%\setcounter{tocdepth}{12}
%\setcounter{secnumdepth}{12}
\newcommand*{\J@Number}{\J@NumberRoot{\value{tiefe}}%
\J@NumberEnd{\value{tiefe}}}
\newcommand*{\J@NumberRoot}[1]{\J@INumberRoot{#1}%
{\csname c@lvl\@alph{#1}\endcsname}}
\newcommand*{\J@INumberRoot}[2]{%
\ifcase#1\or
\@Alph{#2}\or
\@Roman{#2}\or
\@arabic{#2}\or
\@alph{#2}\or
\@alph{#2}\@alph{#2}\or
\@greek{#2}\or
\@greek{#2}\@greek{#2}\or
(\@arabic{#2})\or
(\@alph{#2})\or
(\@alph{#2}\@alph{#2})\or
(\@greek{#2})\or
(\@greek{#2}\@greek{#2})\fi}
\newcommand*{\J@NumberEnd}[1]{\ifnum#1<8\ifnum#1<4.\else)\fi\fi}

\newcommand*{\J@SetCurrent}{\xdef\@currentlabel{{\arabic{lvla}}%
{\arabic{lvlb}}{\arabic{lvlc}}{\arabic{lvld}}{\arabic{lvle}}%
{\arabic{lvlf}}{\arabic{lvlg}}{\arabic{lvlh}}{\arabic{lvli}}%
{\arabic{lvlj}}{\arabic{lvlk}}{\arabic{lvll}}}}

\ifnum\value{lvl\alph{tiefe}}=1%
\PackageWarning{alphanum}{only one subitem in level "\J@Number" ending}%
\fi
\setcounter{lvl\alph{tiefe}}{0}
\addtocounter{tiefe}{-1}

\renewcommand*{\ref}{%
\@ifstar{\@tempswatrue\J@ref}{\@tempswafalse\J@ref}}
\newcommand*{\J@ref}[1]{%
\expandafter\ifx\csname r@#1\endcsname\relax
 \protect\G@refundefinedtrue
 \nfss@text{\reset@font\bfseries ??}
 \@latex@warning{Reference '#1' on page \thepage \space undefined}%
\else
 \expandafter\J@refX\csname r@#1\endcsname
\fi
}
\newcommand*{\J@refX}[1]{\expandafter\J@refXX#1}
\newcommand*{\J@refXX}[2]{%
\ifcat_\ifnum9<1#1_\else X\fi
  #1%
\else
  \expandafter\J@refA#1%
\fi}
\newcommand*{\J@refA}[6]{\@tempcnta\@ne%
\J@refP1{#1}0\J@refP2{#2}{#1}\J@refP3{#3}{#2}\J@refP4{#4}{#3}%
\J@refP5{#5}{#4}\J@refP6{#6}{#5}\J@refB#6}
\newcommand*{\J@refB}[7]{\J@refP7{#2}{#1}\J@refP8{#3}{#2}%
\J@refP9{#4}{#3}\J@refP{10}{#5}{#4}\J@refP{11}{#6}{#5}%
\J@refP{12}{#7}{#6}\J@NumberEnd\@tempcnta}
\newcommand*{\J@refP}[3]{%
\if@tempswa%
 \ifnum#2>0\@tempcnta#1\,\J@INumberRoot{#1}{#2}\fi
\else%
 \ifnum#2=\value{lvl\@alph{#1}}%
  \ifnum#1=12\PackageError{alphanum}{Self-reference detected!}{You used
    a \protect\ref\space in the same section as the referenced
    \protect\label\MessageBreak That makes no sense!}\fi
 \else
  \ifnum#2>0\@tempcnta#1\@tempswatrue\J@INumberRoot{#1}{#2}\else
   \ifnum#3>0%
   \@tempcnta#1\advance\@tempcnta-1\relax\J@INumberRoot{\@tempcnta}{#3}%
   \fi
  \fi
 \fi
\fi}

\makeatother{}




\begin{document}

\section{First}
\label{sec:first}

I'm refering to the second section and I'd like to have a full
reference like this: \ref{sec:secondofsecond}. 

\section{Second}
\label{sec:second}

\subsection{Firstofsecond}
\label{sec:firstofsecond}

Text.

\subsection{Secondofsecond}
\label{sec:secondofsecond}

But now I'm refering to »Firstofsecond« and my readers do not need the
full reference (\ref{sec:firstofsecond}), simply »I.« would be sufficient.

From here a reference to »first of second / second« should look like
this: »1.« and not \ref{sec:first-second-second}

\subsubsection{First of second / second}
\label{sec:first-second-second}

text.


\end{document}

Unfortunately, there is an error (file name: kurze-verweise-mwe.tex):

./kurze-verweise-mwe.tex:134: Missing number, treated as zero.
<to be read again> 
                   I
l.134 ...ence like this: \ref{sec:secondofsecond}.

./kurze-verweise-mwe.tex:134: Missing = inserted for \ifnum.
<to be read again> 

Anybody here who has time and fun to find a solution for one of the two examples?

enter image description here

Keks Dose
  • 30,892
  • 2
    Do you know scrjura? Please see my answer to question http://tex.stackexchange.com/questions/137378/class-available-for-law-reports ... – Mensch Jun 11 '16 at 21:14
  • 2
    Yes, I'm the lawyer "A.W." from KA involved in drafting it. But I fail to see a solution to my question about references which depend on the relative position of label and \ref -- ? – Keks Dose Jun 12 '16 at 09:13
  • Oh, now I understand. That is a misunderstanding: scrjura provides help for contracts, but I'm writing a lengthy pleading, without scrjura. I don't need sections like in german contracts, neither numbered paragraphs. – Keks Dose Jun 12 '16 at 16:48
  • please see http://tex.stackexchange.com/questions/262652/how-to-make-the-enumeration-of-theorem-like-environments-indipendent-from-cross – touhami Aug 15 '16 at 21:20
  • @touhami OK, thank you, but way above my tex skills. How should that work with \ref? – Keks Dose Aug 16 '16 at 06:56
  • Sigh, it is not as easy as I thought first. You didn't do a mistake in the copying, \usepackage{alphanum} leads to the same error. You shall use the jura style of sectioning with \toc, \sub, and \levelup instead of the standard LaTeX style of sectioning that is incompatible with it. – Sir Cornflakes Aug 18 '16 at 12:48
  • @jknappen I can't switch to the jura style, the package is not maintained and KOMA-script is such a good base. But however, thank you very much for your time and effort. – Keks Dose Aug 18 '16 at 16:43

3 Answers3

16

In theory this is not very difficult. You can use zref to store all the various values of section, subsection etc of a label, and then you only need to test their values and compare with the current values and decide what should happen.

In practice it can get a bit tiresome if you really want to do it for all levels as there are quite a number of tests and one normally need a large piece of paper to get all the branches right (I never do on the first attempt).

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel, blindtext}

\setcounter{secnumdepth}{5} % fünf Ebenen



\renewcommand*{\thesection}{\Alph{section}.}
\renewcommand*{\thesubsection}{\Roman{subsection}.}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}.}
\renewcommand*{\theparagraph}{\alph{paragraph})}%)
\renewcommand*{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph})}

\usepackage{zref-user,zref-counter}
\usepackage{expl3}


\makeatletter


\zref@newprop{section}[1]{\the\c@section}
\zref@newprop{subsection}[1]{\the\c@subsection}

\zref@addprop{main}{section}
\zref@addprop{main}{subsection}

\ExplSyntaxOn

\newcommand\myref[1]{%
 \hyperref[#1]{
 \int_compare:nTF
  {
   \zref@extractdefault {#1} {section} {0} = \the\c@section
  }
  {
   %ref is from current section
   \int_compare:nTF
    {\zref@extractdefault {#1} {subsection} {0}  = 0 }
    {Was~nun?}
    {\int_to_Roman:n{\zref@extractdefault {#1} {subsection} {0}}.}
  }
  {
  %ref is from other section
  \int_to_Alph:n  {\zref@extractdefault {#1} {section} {0}}.
  \int_to_Roman:n {\zref@extractdefault {#1} {subsection} {0}}
  }}}

\ExplSyntaxOff
\makeatother
%\usepackage{xcolor}
\usepackage[]{hyperref}

\newcommand\Label[1]{\zlabel{#1}\label{#1}}

\begin{document}

\section{First}
\Label{sec:first}

I'm refering to the second section and I'd like to have a full
reference like this: \myref{sec:secondofsecond}.

\section{Second}
\Label{sec:second}

\myref{sec:secondofsecond}, \myref{sec:first}, \myref{sec:second}

\subsection{Firstofsecond}
\Label{sec:firstofsecond}

Text.

\subsection{Secondofsecond}
\Label{sec:secondofsecond}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • OK, thank you very much! The price of using zref is that you can not click on zref-links in the PDF, and the varioref package no longer works. Next year I'll probably need to send PDFs as files to courts and then clickable references would be nice to have. However, this solution works -- again: thank you! – Keks Dose Aug 18 '16 at 16:40
  • You can add links, you only need also a \label (for the anchors) and then you can add \hyperref[#1]{...} around the text. And you don't need varioref -- everything can be done with zref anyway. – Ulrike Fischer Aug 18 '16 at 16:51
  • So something like \newcommand[1]{\Label}{\zlabel{#1}\label{#}}? And could you give a hint how to add \hyperref[#1]{...} -- I don't understand that part of your comment, sorry! – Keks Dose Aug 18 '16 at 17:06
  • Try \newcommand\myref[1]{\hyperref[#1]{all the complicated code.......}} . – Ulrike Fischer Aug 18 '16 at 17:19
  • Added this and \newcommand{\Label}[1]{\zlabel{#1}\label{#1}} and changed all \zlabel in the document to \Label, but no clickable links. Heiko never merged zref and hyperref, I guess. – Keks Dose Aug 18 '16 at 17:30
  • Work fine for me. I edited the code and added a screenshot. – Ulrike Fischer Aug 18 '16 at 17:40
  • Got it, but found a "bug": If you add more levels, subsubsections and paragraphs, the displayed link always is a "II.", I'll print the code in my question. – Keks Dose Aug 18 '16 at 18:23
  • I warned you that getting all the if-switches right isn't easy ; -) It needs quite some time. So I added only the code for two levels. You will have to extend it. – Ulrike Fischer Aug 18 '16 at 18:35
  • I slightly doubt that I can extend code of LaTeX3 I don't even understand in a case you find complicated -- much above my skills. Maybe you can add some comments into the code, what you are doing? :-) – Keks Dose Aug 18 '16 at 18:56
  • It is not complicated, you only have a large number of branches and tests that you must sort correctly. The latex3 code is rather small, you only have a test (\int_compare:nTF { x = y?? } { true }{false}) and some conversions from numbers to Alpha or Roman. – Ulrike Fischer Aug 19 '16 at 13:46
  • See below, I found a solution, but it took a whole day and I can't say that I understood everthing... You are right: a large number of branches. – Keks Dose Aug 21 '16 at 20:50
4

Are you aware of the jura package? Altho' it is quite old and unsupported, it provides the fine grade level structure you sketch (and goes even further down to levels indicated by α) β) and αα) ββ)

EDIT: Note that the document markup introduced with jura (or with \usepackage{alphanum} that contains the level structure) is incompatible with the usual LaTeX sectioning commands (like \section etc.). You shall use the jura style of sectioning using \toc, \sub, and \levelup.

  • It unfortunately is a documentclass. I depend in many ways on KOMA-script and can't change. But you made a good pick: on p. 4 the manual describes exactly the behaviour I'd like to have. Do you think it needs much time and effort to extract those lines from the source? I'm lacking programmings skills... – Keks Dose Aug 10 '16 at 14:59
  • It looks feasible to extract the relevant lines of LaTeX code. The code is even documented. – Sir Cornflakes Aug 10 '16 at 15:16
  • OK, jura.dtx includes code, but at least I can not extract only the relevant parts. There are to many macros (that lvl-stuff) too deeply implemented in the machinery of jura.dtx. – Keks Dose Aug 12 '16 at 13:12
  • I suggest just to put the whole stuff starting from section 3.4 Neue Makros up to section 3.5.3 Sachverhalt into a LateX package and add some LaTeX package headers. Depending on your main documentclass, you may want to delete sections 3.4.1 Fußnoten and 3.4.2 Dokumentstruktur. I won't be afraid of the lvl-stuff, it should not hurt you even if you don't use it. – Sir Cornflakes Aug 16 '16 at 09:49
4

The answer of Ulrike Fischer showed me the way and after poring over it for a whole day I found the following solution.

Probably it is the lowest level of coding you ever will read, so be warned. If someone comes up with a better solution: very well!

But without Ulrikes generous help, it would not have been possible, thank you very much!

Some comments are in German, sorry, it is late now and I doubt that I tommorrow will understand, what I wrote today! Ah, and the various, useless "(" in comments are there to make Emacs happy, which otherwise doesn't get the "{" and "}" matched.

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel, blindtext}

\setcounter{secnumdepth}{5} % fünf Ebenen



\renewcommand*{\thesection}{\Alph{section}.}
\renewcommand*{\thesubsection}{\Roman{subsection}.}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}.}
\renewcommand*{\theparagraph}{\alph{paragraph})}%)
\renewcommand*{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph})}

\usepackage{zref-user, zref-counter}
\usepackage{expl3}


\makeatletter


\zref@newprop{section}[1]{\the\c@section}
\zref@newprop{subsection}[1]{\the\c@subsection}
\zref@newprop{subsubsection}[1]{\the\c@subsubsection}
\zref@newprop{paragraph}[1]{\the\c@paragraph}
\zref@newprop{subparagraph}[1]{\the\c@subparagraph}

\zref@addprop{main}{section}
\zref@addprop{main}{subsection}
\zref@addprop{main}{subsubsection}
\zref@addprop{main}{paragraph}
\zref@addprop{main}{subparagraph}

\ExplSyntaxOn

\newcommand\myref[1]{%
 \hyperref[#1]{%
  \int_compare:nTF
  {% A.-Ebene prüfen: sind wir auf dem gleichen Zweig? 
   \zref@extractdefault {#1} {section} {0} = \the\c@section
  }
  { % Ja, wir sind auf dem gleichen Zweig
    % Existiert eine weitere Ebene?
    \int_compare:nTF
    {\zref@extractdefault {#1} {subsection} {0}  = 0}
    % Wenn subsection 0 ist, also nicht existiert, dann muss section ausgegeben
    % werden. 
    {
     % \emph{Fehlerhafter Verweis}
    \int_to_Alph:n  {\zref@extractdefault {#1} {section} {0}}.
    }
    % Wenn dagegen subsection existiert, dann geht die Prüfung weiter:
    {
     % OK, weitere ebene existiert. 
     \int_compare:nTF % I.-Ebene
      {
        \zref@extractdefault {#1} {subsection} {0}  = \the\c@subsection 
      }% Sind wir auf der gleichen I.-Ebene?
      {% I.-Ebene: Gleiche Ebene
        % Prüfung: gibt es eine weitere Ebene?
        \int_compare:nTF
        {\zref@extractdefault {#1} {subsubsection} {0} = 0}
        {% Wenn 0, dann keine weitere Ebene und subsection ausgeben:
          \int_to_Roman:n {\zref@extractdefault {#1} {subsection} {0}}.
        }
        {% OK, weitere Ebene existiert
              \int_compare:nTF % subsubsection-Ebene
                {% 1.-Ebene prüfen
                  \zref@extractdefault {#1} {subsubsection} {0} = \the\c@subsubsection  
                }
                {% 1.-Ebene ist gleich
                  %Prüfung: gibt es eine weitere Ebene?
                  \int_compare:nTF % Gibt es eine a-Ebene?
                  {\zref@extractdefault {#1} {paragraph} {0} =  0}
                  {% Wenn 0, dann keine weitere Ebene und subsubsection ausgeben:
                    \int_to_arabic:n { \zref@extractdefault {#1} {subsubsection} {0}}.
                  }
                  {% Paragraph existiert:
                   \int_compare:nTF % a-Ebene prüfen
                    {
                      \zref@extractdefault {#1} {paragraph} {0} =  \the\c@paragraph
                    }
                    {% a-Ebene ist gleich
                      % Prüfung: aa-Ebene vorhanden?
                      \int_compare:nTF % 
                      { \zref@extractdefault {#1} {subparagraph} {0} =  0}
                      %
                      {%( damit emacs happy ist
                        \int_to_alph:n {\zref@extractdefault {#1} {paragraph} {0} })
                      }
                      {% aa-Ebene vorhanden
                        \int_compare:nTF
                        {\zref@extractdefault {#1} {subparagraph} {0} = \the\c@subparagraph}
                        {\emph{Fehlerhafter VERWEIS}}
                        %( make emacs happy
                        {\int_to_alph:n { \zref@extractdefault {#1} {subparagraph}   {0}   }
                        \int_to_alph:n { \zref@extractdefault {#1} {subparagraph} {0}   })
                        }
                      }
                    }
                    {% a-Ebene ist unterschiedlich (
                      \int_to_alph:n{\zref@extractdefault {#1} {paragraph} {0}})
                    }
                  }
                }
                {% 1.-Ebene ist unterschiedlich 
                  \int_to_arabic:n{\zref@extractdefault {#1} {subsubsection} {0}}.
                }
         }% 3. Klammer Prüfung, ob subsection existiert (also wenn ja)
    }   
     {% I.-Ebene: ungleich
       % Also römische Nummer ausgeben
         \int_to_Roman:n{\zref@extractdefault {#1} {subsection} {0}}.%
          \int_compare:nTF%existiert die nächste Ebene?
           { \zref@extractdefault {#1} {subsubsection} {0} = 0 }
           {}% = 0, subsubsection nicht vorhanden
           {% ungleich 0
            % also arabische Zahl ausgeben
             \int_to_arabic:n { \zref@extractdefault {#1} {subsubsection} {0}}.
               \int_compare:nTF%existiert die nächste Ebene paragraph?
               { \zref@extractdefault {#1} {paragraph} {0} = 0 }
               {}% = 0, subsubsection nicht vorhanden
               {% ungleich 0 (
                 \int_to_alph:n { \zref@extractdefault {#1} {paragraph} {0}})
               }
               % subpar Ebene vorhanden?
               \int_compare:nTF
               { \zref@extractdefault {#1} {subparagraph} {0} = 0}
               {}% ja, also existiert subpar nicht 
               { %(
                 \int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}}
                 \int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}})
               }
           }
       }% 3. Klammer I.-Ebene
  }% 3. Klammer Prüfung, ob I. Ebene besteht.
  }% 2. Klammer A.-Ebene
  {% A.-Ebene: Ungleich
  %ref is from other section
  \int_to_Alph:n  {\zref@extractdefault {#1} {section} {0}}.
    \int_compare:nTF%existiert die nächste Ebene?
    { \zref@extractdefault {#1} {subsection} {0} = 0 }
    {}% ja, erfüllt, keine subsection
    {% subsection existiert:
      \int_to_Roman:n {\zref@extractdefault {#1} {subsection} {0}}.
      \int_compare:nTF%existiert die nächste Ebene?
          { \zref@extractdefault {#1} {subsubsection} {0} = 0 }
          {}% = 0, subsubsection nicht vorhanden
          {% ungleich 0
            \int_to_arabic:n { \zref@extractdefault {#1} {subsubsection} {0} }.
             \int_compare:nTF%existiert die nächste Ebene paragraph?
              { \zref@extractdefault {#1} {paragraph} {0} = 0 }
              {}% = 0, paragraph nicht vorhanden
              {% ungleich 0 (
                \int_to_alph:n { \zref@extractdefault {#1} {paragraph} {0} })
                \int_compare:nTF
                { \zref@extractdefault {#1} {subparagraph} {0} = 0}
                {}% ja, also existiert subpar nicht
                {% (
                  \int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}}
                  \int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}})
                }
              }
          }
       }
  }% 3. Klammer A.-Ebene
}% hyperref Klammer zu
}%Ende Befehlsdefinition myref

\ExplSyntaxOff
\makeatother

\usepackage[]{hyperref}

\newcommand\Label[1]{\zlabel{#1}\label{#1}}

\begin{document}

\textbf{Präambel}

\begin{enumerate}
  \item Reference to first section: \myref{sec:first}
  \item Reference to second section: \myref{sec:second}
  \item Reference to snd section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to snd sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to snd sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to snd sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
  \item Subparagraph: \myref{CLA:first-sub}
\end{enumerate}


\section{First}
\Label{sec:first}

Sytematically:
\begin{enumerate}
  \item Reference to this section should display a warning: \myref{sec:first}.
  \item Reference to next section: \myref{sec:second}
  \item Reference to next section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to next sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to next sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to next sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
  \item Subparagraph: \myref{CLA:first-sub}
\end{enumerate}


\section{Second}
\Label{sec:second}

Sytematically:
\begin{enumerate}
  \item Reference to previous section: \myref{sec:first}.
  \item Reference to this section should display a warning: \myref{sec:second}
  \item Reference to this section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to this sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to this sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to this sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
  \item Subparagraph: \myref{CLA:first-sub}
\end{enumerate}


\subsection{Firstofsecond}
\Label{sec:firstofsecond}

Sytematically:
\begin{enumerate}
  \item Reference to previous section: \myref{sec:first}.
  \item Reference to this section: \myref{sec:second}
  \item Reference to this section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to this sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to this sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to this sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
  \item Subparagraph: \myref{CLA:first-sub}
\end{enumerate}


\subsection{Secondofsecond}
\Label{sec:secondofsecond}


Now down the tree:

\subsubsection{first of second.second}
\Label{CLA:first-second.second}

Just some letters. 

\paragraph{first-paragraph}
\Label{CLA:first-paragraph}

And more text. Ref to next paragraph, should be a b): \myref{CLA:second-paragr}

\begin{enumerate}
  \item Reference to previous section: \myref{sec:first}.
  \item Reference to this section: \myref{sec:second}
  \item Reference to this section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to this sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to this sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to this sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
  \item Subparagraph: \myref{CLA:first-sub}
\end{enumerate}



\paragraph{second paragr}
\Label{CLA:second-paragr}

\begin{enumerate}
  \item Reference to previous section: \myref{sec:first}.
  \item Reference to this section: \myref{sec:second}
  \item Reference to this section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to this sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to this sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to this sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
\end{enumerate}

\subparagraph{first sub}
\Label{CLA:first-sub}

\begin{enumerate}
  \item Reference to previous section: \myref{sec:first}.
  \item Reference to this section: \myref{sec:second}
  \item Reference to this section / first subsection: \myref{sec:firstofsecond}
  \item Ref. to this sect. / second subsect: \myref{sec:secondofsecond}
  \item Ref to this sect. / second subsect / first arabic:
  \myref{CLA:first-second.second}
  \item Ref. to this sect. / second subsect / first arabic / second par:
  \myref{CLA:second-paragr}
  \item Subparagraph: \myref{CLA:first-sub}
\end{enumerate}


dsfsdf


\subsubsection{Last one}
\Label{CLA:last-one}

text

\paragraph{paragraph somewhere}
\Label{CLA:paragraph-somewhere}

OK, the par above should display a). And now we refer to the next subpar:
\myref{CLA:second-subpar}.

And now a subpar:

\subparagraph{second subpar}
\Label{CLA:second-subpar}

text

\subparagraph{third subpar}





\end{document}
Keks Dose
  • 30,892