Benjamin-Loison / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
0 stars 0 forks source link

Automatically create labels for `\caption`s #4

Open Benjamin-Loison opened 9 months ago

Benjamin-Loison commented 9 months ago

How to deal with $x=1$, \cite{...} and \emph{...}?

Related to #3.

Brief outline of the enhancement

LaTeX2e generally cannot add new features without an extreme amount of care to accommodate backwards compatibility. Please do not be offended if your request is closed for being infeasible.

Minimal example showing the current behaviour

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

  % Any preamble code goes here

\begin{document}

  % Demonstration of issue here

\end{document}

Minimal example showing the desired new behaviour

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

  % Any preamble code goes here

\begin{document}

  % Demonstration of issue here

\end{document}
Benjamin-Loison commented 3 months ago
\newcommand{\myLabel}[2]{\label{#1:#2}#2}
\subsection{\myLabel{section}{Motivation}}

is a first working iteration.

Benjamin-Loison commented 3 months ago
\caption{\label{figure:Simplified image processing pipeline, and noise curve associated with each step}Simplified image processing pipeline, and noise curve associated with each step~\cite{bayer}.}
\caption{\myLabel{figure}{Simplified image processing pipeline, and noise curve associated with each step}~\cite{bayer}.}

looks like an interesting second iteration.

Benjamin-Loison commented 3 months ago

Avoiding specifying first argument would be nice.

Benjamin-Loison commented 3 months ago
grep '\myLabel{' article.tex
grep -vE '\\(caption\{\\myLabel\{(|sub)figure|(|sub(|sub))section\{\\myLabel\{section)\}\{' article.tex | grep '\myLabel{'

is exhaustive.

So:

Parent node name What I would like to get
caption figure or subfigure
{,{,sub}}section section

Maybe better \label prefix could be used.

I am looking for a function, command or variable that returns the parent node name for instance \section{My \getParentNodeName} would be equivalent to \section{My section} and \caption{My \getParentNodeName} would be equivalent to \caption{My caption}.

LaTeX get parent node does not seem to return interesting results on DuckDuckGo and Google.

The Tex Stack Exchange question 464119 is about getting the parent section name so not what I am looking for.