0

I want to create a macro which will reference a given section (or chapter, part, subsection, etc.) but if the section referenced is the next section after the current one, it will say "the next section" rather than "Section X", and the same for the previous section and "the previous section". What I'm imagining the pseudocode would look like is something like this:

\usepackage{\ifthen}

\newcommand{\secref}[1]{
    \ifthenelse{\equal{\thesection}{\ref{#1}-1}}
        {the next section}
    {\ifthenelse{\equal{\thesection}{\ref{#1}+1}}
        {the previous section}
    {Section #1}}}

Is there a package for this? And if not, how would I go about creating a solution?

3
  • 3
    Note that Section 1 in Chapter 1 is not the "previous" section for Section 2 in Chapter 2 (say). Do you have chapters? Do you have parts?
    – Werner
    Commented Sep 16, 2019 at 17:54
  • Good point! I would ideally have something that would work on multiple levels within article class (though a solution that also works in memoir would be great as well). It would need to know not to reference Sec 2 Chap 2 as the "next section" but the Sec 1 Chap 2 would also not need to be the "next section" after the last section of Chap 1
    – Jackirab
    Commented Sep 16, 2019 at 18:00
  • 3
    \section, \subsection, \subsubsection is LaTeX terminology for distinguishing the depth of numbering of -well- section-headings. Outside LaTeX terminology there is more than one "sectioning doctrine". In many "sectioning doctrines", e.g., section 1.7 does not contain subsection 1.7.1 but section 1.7 ends and section 1.7.1 begins. With such doctrines a section 1.7 is the previous section of section 1.7.1, while section 1.7.1 is the previous section of section 1.7.2, which in turn is the previous section of section 1.7.2.1 which in turn might be the previous section of section 1.8. Commented Sep 16, 2019 at 18:39

0

Browse other questions tagged .