Referencing parent(s) of labels












1














I'm trying to reference a label's parent so it outputs something like "Section, Subsection" or "Section, Subsection, Subsubsection". I've come close with smartref by doing the following:



usepackage{smartref}
addtoreflist{section}

newcommand{breadref}[1]{sectionref{#1}, fullref{#1}}


but this unfortunately only outputs the number of the section and not the name of the section. The documentation of smartref alludes to a byname option but doesn't seem to actually provide a working example of it, making it difficult to implement.



It seems like this should be an easy thing to do, and a useful thing at that, especially if subsections might move between sections making hard-coded references to parents a pain.



Any ideas would be appreciated.



Mike



EDIT:



Ideally, it would look like this:



sketch of desired output










share|improve this question
























  • I think you want to have a look at nameref and cleveref.
    – egreg
    Dec 10 at 12:54










  • @egreg I had a look at these packages but couldn't find what I was looking for. Think you could point me in the right direction or put together an answer?
    – Mackey18
    Dec 10 at 12:55










  • Please, add a sketch of the expected output.
    – egreg
    Dec 10 at 13:09










  • @egreg Added to main question
    – Mackey18
    Dec 10 at 13:55
















1














I'm trying to reference a label's parent so it outputs something like "Section, Subsection" or "Section, Subsection, Subsubsection". I've come close with smartref by doing the following:



usepackage{smartref}
addtoreflist{section}

newcommand{breadref}[1]{sectionref{#1}, fullref{#1}}


but this unfortunately only outputs the number of the section and not the name of the section. The documentation of smartref alludes to a byname option but doesn't seem to actually provide a working example of it, making it difficult to implement.



It seems like this should be an easy thing to do, and a useful thing at that, especially if subsections might move between sections making hard-coded references to parents a pain.



Any ideas would be appreciated.



Mike



EDIT:



Ideally, it would look like this:



sketch of desired output










share|improve this question
























  • I think you want to have a look at nameref and cleveref.
    – egreg
    Dec 10 at 12:54










  • @egreg I had a look at these packages but couldn't find what I was looking for. Think you could point me in the right direction or put together an answer?
    – Mackey18
    Dec 10 at 12:55










  • Please, add a sketch of the expected output.
    – egreg
    Dec 10 at 13:09










  • @egreg Added to main question
    – Mackey18
    Dec 10 at 13:55














1












1








1







I'm trying to reference a label's parent so it outputs something like "Section, Subsection" or "Section, Subsection, Subsubsection". I've come close with smartref by doing the following:



usepackage{smartref}
addtoreflist{section}

newcommand{breadref}[1]{sectionref{#1}, fullref{#1}}


but this unfortunately only outputs the number of the section and not the name of the section. The documentation of smartref alludes to a byname option but doesn't seem to actually provide a working example of it, making it difficult to implement.



It seems like this should be an easy thing to do, and a useful thing at that, especially if subsections might move between sections making hard-coded references to parents a pain.



Any ideas would be appreciated.



Mike



EDIT:



Ideally, it would look like this:



sketch of desired output










share|improve this question















I'm trying to reference a label's parent so it outputs something like "Section, Subsection" or "Section, Subsection, Subsubsection". I've come close with smartref by doing the following:



usepackage{smartref}
addtoreflist{section}

newcommand{breadref}[1]{sectionref{#1}, fullref{#1}}


but this unfortunately only outputs the number of the section and not the name of the section. The documentation of smartref alludes to a byname option but doesn't seem to actually provide a working example of it, making it difficult to implement.



It seems like this should be an easy thing to do, and a useful thing at that, especially if subsections might move between sections making hard-coded references to parents a pain.



Any ideas would be appreciated.



Mike



EDIT:



Ideally, it would look like this:



sketch of desired output







sectioning cross-referencing packages






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 10 at 13:55

























asked Dec 10 at 12:08









Mackey18

1084




1084












  • I think you want to have a look at nameref and cleveref.
    – egreg
    Dec 10 at 12:54










  • @egreg I had a look at these packages but couldn't find what I was looking for. Think you could point me in the right direction or put together an answer?
    – Mackey18
    Dec 10 at 12:55










  • Please, add a sketch of the expected output.
    – egreg
    Dec 10 at 13:09










  • @egreg Added to main question
    – Mackey18
    Dec 10 at 13:55


















  • I think you want to have a look at nameref and cleveref.
    – egreg
    Dec 10 at 12:54










  • @egreg I had a look at these packages but couldn't find what I was looking for. Think you could point me in the right direction or put together an answer?
    – Mackey18
    Dec 10 at 12:55










  • Please, add a sketch of the expected output.
    – egreg
    Dec 10 at 13:09










  • @egreg Added to main question
    – Mackey18
    Dec 10 at 13:55
















I think you want to have a look at nameref and cleveref.
– egreg
Dec 10 at 12:54




I think you want to have a look at nameref and cleveref.
– egreg
Dec 10 at 12:54












@egreg I had a look at these packages but couldn't find what I was looking for. Think you could point me in the right direction or put together an answer?
– Mackey18
Dec 10 at 12:55




@egreg I had a look at these packages but couldn't find what I was looking for. Think you could point me in the right direction or put together an answer?
– Mackey18
Dec 10 at 12:55












Please, add a sketch of the expected output.
– egreg
Dec 10 at 13:09




Please, add a sketch of the expected output.
– egreg
Dec 10 at 13:09












@egreg Added to main question
– Mackey18
Dec 10 at 13:55




@egreg Added to main question
– Mackey18
Dec 10 at 13:55










1 Answer
1






active

oldest

votes


















1














With some tweaks!



However, you need to use sectionlabel for sections and subsectionlabel for subsections and not just label, because we need to add functionality.



documentclass{article}
usepackage[byname]{smartref}

makeatletter
newcommand{subsectionlabel}[1]{%
label{#1}%
@bsphack
protected@write@auxout{}{stringnewparent{#1}{@currentsectionlabel}}%
@esphack
}
newcommand{sectionlabel}[1]{%
label{#1}%
@bsphackgdef@currentsectionlabel{#1}@esphack
}
newcommand{newparent}[2]{%
global@namedef{parent@#1}{#2}%
}

newcommand{broadref}[1]{%
byname{@nameuse{parent@#1}}, byname{#1}~(ref{#1})%
}
makeatother


begin{document}

section{My section}sectionlabel{sec:mysection}

Some text.

subsection{My subsection}subsectionlabel{subsec:mysubsection}

Some text.

section{Reference section}

This is a reference to the subsection:
broadref{subsec:mysubsection}

end{document}


enter image description here






share|improve this answer





















  • Even though I don't really understand what's going on here, it worked perfectly.
    – Mackey18
    Dec 11 at 11:53











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464119%2freferencing-parents-of-labels%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














With some tweaks!



However, you need to use sectionlabel for sections and subsectionlabel for subsections and not just label, because we need to add functionality.



documentclass{article}
usepackage[byname]{smartref}

makeatletter
newcommand{subsectionlabel}[1]{%
label{#1}%
@bsphack
protected@write@auxout{}{stringnewparent{#1}{@currentsectionlabel}}%
@esphack
}
newcommand{sectionlabel}[1]{%
label{#1}%
@bsphackgdef@currentsectionlabel{#1}@esphack
}
newcommand{newparent}[2]{%
global@namedef{parent@#1}{#2}%
}

newcommand{broadref}[1]{%
byname{@nameuse{parent@#1}}, byname{#1}~(ref{#1})%
}
makeatother


begin{document}

section{My section}sectionlabel{sec:mysection}

Some text.

subsection{My subsection}subsectionlabel{subsec:mysubsection}

Some text.

section{Reference section}

This is a reference to the subsection:
broadref{subsec:mysubsection}

end{document}


enter image description here






share|improve this answer





















  • Even though I don't really understand what's going on here, it worked perfectly.
    – Mackey18
    Dec 11 at 11:53
















1














With some tweaks!



However, you need to use sectionlabel for sections and subsectionlabel for subsections and not just label, because we need to add functionality.



documentclass{article}
usepackage[byname]{smartref}

makeatletter
newcommand{subsectionlabel}[1]{%
label{#1}%
@bsphack
protected@write@auxout{}{stringnewparent{#1}{@currentsectionlabel}}%
@esphack
}
newcommand{sectionlabel}[1]{%
label{#1}%
@bsphackgdef@currentsectionlabel{#1}@esphack
}
newcommand{newparent}[2]{%
global@namedef{parent@#1}{#2}%
}

newcommand{broadref}[1]{%
byname{@nameuse{parent@#1}}, byname{#1}~(ref{#1})%
}
makeatother


begin{document}

section{My section}sectionlabel{sec:mysection}

Some text.

subsection{My subsection}subsectionlabel{subsec:mysubsection}

Some text.

section{Reference section}

This is a reference to the subsection:
broadref{subsec:mysubsection}

end{document}


enter image description here






share|improve this answer





















  • Even though I don't really understand what's going on here, it worked perfectly.
    – Mackey18
    Dec 11 at 11:53














1












1








1






With some tweaks!



However, you need to use sectionlabel for sections and subsectionlabel for subsections and not just label, because we need to add functionality.



documentclass{article}
usepackage[byname]{smartref}

makeatletter
newcommand{subsectionlabel}[1]{%
label{#1}%
@bsphack
protected@write@auxout{}{stringnewparent{#1}{@currentsectionlabel}}%
@esphack
}
newcommand{sectionlabel}[1]{%
label{#1}%
@bsphackgdef@currentsectionlabel{#1}@esphack
}
newcommand{newparent}[2]{%
global@namedef{parent@#1}{#2}%
}

newcommand{broadref}[1]{%
byname{@nameuse{parent@#1}}, byname{#1}~(ref{#1})%
}
makeatother


begin{document}

section{My section}sectionlabel{sec:mysection}

Some text.

subsection{My subsection}subsectionlabel{subsec:mysubsection}

Some text.

section{Reference section}

This is a reference to the subsection:
broadref{subsec:mysubsection}

end{document}


enter image description here






share|improve this answer












With some tweaks!



However, you need to use sectionlabel for sections and subsectionlabel for subsections and not just label, because we need to add functionality.



documentclass{article}
usepackage[byname]{smartref}

makeatletter
newcommand{subsectionlabel}[1]{%
label{#1}%
@bsphack
protected@write@auxout{}{stringnewparent{#1}{@currentsectionlabel}}%
@esphack
}
newcommand{sectionlabel}[1]{%
label{#1}%
@bsphackgdef@currentsectionlabel{#1}@esphack
}
newcommand{newparent}[2]{%
global@namedef{parent@#1}{#2}%
}

newcommand{broadref}[1]{%
byname{@nameuse{parent@#1}}, byname{#1}~(ref{#1})%
}
makeatother


begin{document}

section{My section}sectionlabel{sec:mysection}

Some text.

subsection{My subsection}subsectionlabel{subsec:mysubsection}

Some text.

section{Reference section}

This is a reference to the subsection:
broadref{subsec:mysubsection}

end{document}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 10 at 14:50









egreg

708k8618823163




708k8618823163












  • Even though I don't really understand what's going on here, it worked perfectly.
    – Mackey18
    Dec 11 at 11:53


















  • Even though I don't really understand what's going on here, it worked perfectly.
    – Mackey18
    Dec 11 at 11:53
















Even though I don't really understand what's going on here, it worked perfectly.
– Mackey18
Dec 11 at 11:53




Even though I don't really understand what's going on here, it worked perfectly.
– Mackey18
Dec 11 at 11:53


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464119%2freferencing-parents-of-labels%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?