1

Note the focus of this question changed slightly. See my answer for further clarification!

I would like to make certain references/links dependent on where exactly I put certain content in my document. While the actual linking works well as it seems, I have problems with the desired presentation.

Say, I have the two folders on my computer "current projects" and "finished projects" and the corresponding sections (or paragraphs or whatever) in the document. The aim is now to be able to change the reference just by coping a line of code from one section to the other. This is accomplished with the zref-titleref package e.g. together with hyperref for the functional part and - if possible - menukeys for the presentation. Yet, the directory path for menukeys always breaks, and I'm not able to find a way to make both aspects of it work as desired.

Please have a look at the folling code:

    \documentclass{article}

    \usepackage{catchfilebetweentags}

    \newcommand{\loadProject}[1]{\ExecuteMetaData["C:/Users/Pippo/Documents/Projects/Current Projects/Projectcontent.tex"]{#1}}

    \usepackage[os=win]{menukeys}
    \renewmenumacro{\menu}[>]{roundedmenus} % default: menus
    \renewmenumacro{\directory}[/]{hyphenatepathswithfolder} % default: paths
    \renewmenumacro{\keys}[+]{shadowedroundedkeys} % default: roundedkeys

    \usepackage{zref-titleref}

    \makeatletter
    \newcommand*{\currentname}{\zref@getcurrent{title}}
    \makeatother

    \usepackage{hyperref}

    \begin{document}

    \section{Current Projects}

    \loadProject{proj:Project 1}

    \section{Finished Projects}

    \end{document}

and in the catchfilebetweentags-file something like

   %<*proj:Project1>

   \href{run:C:/Users/Pippo/Documents/Projects/\currentname/.}{\directory{C:/Users/Pippo/Documents/Projects/\currentname}}

   %</proj:Project1>

Is it somehow possible to make this work and have the link typeset as it should be. Note that the menukeys string usually works in the hyperlink and also that there are other packages allowing for referencing the section name (see https://tex.stackexchange.com/a/75183/91897 ), yet so far I have not been able to find a solution.

Xima
  • 113
  • If you have already found a solution, you can post an answer to your own question. Maybe it could be useful for other users in future. Thank you! – CarLaTeX May 16 '17 at 01:15

1 Answers1

1

I didn't post this answer right away, since, after a minor edit, the code above already ran with the desired results at that moment. Yet I figured out that it wasn't really sensible to what I was trying to do... The \currentname string actually should stay on the section level and not reference the currentlabel each time a new subsection is introduced.

To achieve this I put

\newcommand{\thirdoffive}[5]{#3}
\newcommand{\assignnameref}[2]{%
   \gdef#2{}% Assign macro to be blank
 \ifcsname r@#1\endcsname%
\xdef#2{\expandafter\expandafter\expandafter\thirdoffive\csname r@#1\endcsname}%
\fi
}

in the preamble. And start the relevant sections with

 \subsection{Current Projects}\label{sec:curProjects}
 \assignnameref{sec:curProjects}{\currentname}%

And together with the code from the question it works like that charm! It does require a couple of runs though, of course, if new labels are introduced.

Sebastiano
  • 54,118
Xima
  • 113