GeneralFull context variable depth references to list labels?

LaTeX specific issues not fitting into one of the other forums of this category.
kreil
Posts: 11
Joined: Mon Jul 28, 2008 3:38 am

Re: Full context variable depth references to list labels?

Post by kreil »

Ah, ok, so I can either

1) use the version with an explicitly \savedlabel
2) use the version with \@currentlabel, as long as I don't nest our environment in other environments that used refstepcounter (which is actually, quite likely)
or
3) use a version that directly probes the section levels -- but to get that generic, I'd have to check subsection, subsubsection etc.

I think for now I'm quite fine with (2) there. If I need to tag a full-section context to some other label I can use \cc with (1).

Your suggestion using AMSmath and numberwithin is neat but only fixes equations. It would be really nice to just turn on full-context labels globally. If I were better with LaTeX coding, I'd then go and try to write a clever \ref command that allows relative references, e.g., if I'm in section 2.3, then a reference to 2.3-4 would just be 4, but if I'm elsewhere it would be 2.3-4, etc.

Thanks again for your suggestions, I've been learning a lot!

All the best,
David.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Ted
Posts: 94
Joined: Sat Jun 23, 2007 4:11 pm

Full context variable depth references to list labels?

Post by Ted »

kreil wrote:1) use the version with an explicitly \savedlabel
2) use the version with \@currentlabel, as long as I don't nest our environment in other environments that used refstepcounter (which is actually, quite likely)
or
3) use a version that directly probes the section levels -- but to get that generic, I'd have to check subsection, subsubsection etc.

I think for now I'm quite fine with (2) there. If I need to tag a full-section context to some other label I can use \cc with (1).
Why are you unhappy with (3)? I thought your only requirement is that the SUBSECTION (or section) is prefixed. Must you prefix with the least-significant section? That is, if you have subsubsections, you have to check for them TOO? If so, use the following:

Code: Select all

\usepackage{enumitem}
\newlist{legal}{enumerate}{10}
\makeatletter
\newcommand\savesectionlabel{\protected@edef\savedlabel{\@currentlabel\relax\relax}}
\setlist[legal]{label*=\arabic*.,ref=\csname the\enit@prevlabel\endcsname\arabic*.}
\newcommand{\thelegal}{\savedlabel-}
\let\origSection\section
\let\origSubsection\subsection
\let\origSubsubsection\subsubsection
\newcommand\newSectionstar{\origSection*}
\newcommand\newSubsectionstar{\origSubsection*}
\newcommand\newSubsubsectionstar{\origSubsubsection*}
\newcommand\newSection[1]{\origSection{#1}\savesectionlabel}
\newcommand\newSubsection[1]{\origSubsection{#1}\savesectionlabel}
\newcommand\newSubsubsection[1]{\origSubsubsection{#1}\savesectionlabel}
\renewcommand\section{\@ifstar\newSectionstar\newSection}
\renewcommand\subsection{\@ifstar\newSubsectionstar\newSubsection}
\renewcommand\subsubsection{\@ifstar\newSubsubsectionstar\newSubsubsection}
\makeatother

\usepackage{varioref}
\labelformat{equation}{\savedlabel-\textup{(#1)}}
\labelformat{figure}{\savedlabel-#1}
\labelformat{table}{\savedlabel-#1}
Of course, you can add more \labelformat lines if you wish.
kreil wrote:Your suggestion using AMSmath and numberwithin is neat but only fixes equations. It would be really nice to just turn on full-context labels globally.
Please re-read that post. I show you how to use varioref's \labelformat to do what I think is exactly what you want. Sure, it's not "global," but it's not THAT big of a deal to add one more \labelformat line for each counter you need to use (note that the snippet above includes those varioref lines). (notice that this solution does not require amsmath)

[ Aside: Keep in mind that \numberwithin applies to more than just equations. You can use \numberwithin for any counter. ]
-- Ted [home/blog]
kreil
Posts: 11
Joined: Mon Jul 28, 2008 3:38 am

Re: Full context variable depth references to list labels?

Post by kreil »

Yes, that looks good, thanks!

The reason I need support for different depths is that I am struggling with a large, structured document, that I am desparately trying to get into some *readable* order. At the same time, I need to preserve the structure, while allowing references from the outside (a stupid form I need to fill in).

Anyway, all this has helped me an awful lot so I can now focus the rest of the week on actually writing the text and moving things about! :-)

If you ever pass through Vienna (AT) let me know, I owe you a drink! :)

Best wishes,
David.
cpp
Posts: 3
Joined: Wed Oct 08, 2014 6:59 am

Re: Full context variable depth references to list labels?

Post by cpp »

Hi, I am not an expert. I've been using this technique to produce legal references, but

1. the references all have a trailing "." which makes it hard to read.
2. I am not able to see nested enumerations where the innermost is a alphabet.

Ideally, I'd like to have a reference like 1.2(1)(a) where 1 is a section, 1.2 is the subsection, and (1)(a) is an enumeration and a is a nested enumeration. But I'm not picky!!!

Have experimented a lot but no luck. Its kinda urgent so if someone can have pity and give me a shortcut I'll find a way to contribute back into the community soon!
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Full context variable depth references to list labels?

Post by Johannes_B »

Hi, you are highjacking a very old question. I think opening a new thread would be the very best option. New topic, new base, better to find for others searching for a similar matter.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply