TransWikia.com

Context sensitive cross reference using Cleveref and Varioref

TeX - LaTeX Asked on March 8, 2021

I am blocked to make a command (called pref{<cross-reference>}) for cross-references using cleveref and varioref. I would like it to be able to adapt to the context :

  • First, I would like to be able to remove the comma when the reference is on the same page as the referenced object. This is what I currently have :
    enter image description here

  • Secondly, I would have liked to know if it was possible to add the name of the chapter or section to which reference is made without calling on crefformat and thus be able to use the command cref with its default behavior in other contexts.

Here’s what I currently have:
enter image description here

Here’s what I’d like to be able to post:
enter image description here

documentclass{article}
usepackage{varioref, hyperref, cleveref}
setlength{parindent}{0pt}
defreftextcurrent{}
defreftextfaraway#1{p.~pageref{#1}}
crefformat{figure}{#2textsc{Fig.}~#1#3}
crefformat{section}{#2textsc{Sec.}~#1#3}

newcommand{pref}[1]{(cref{#1}, vpageref{#1})}

begin{document}
pref{fig1}qquadpref{sec1}

clearpage
pref{fig1}qquadpref{sec1}
(cref{sec1} : textit{nameref{sec1}}, vpageref{sec1})% desired behaviour

clearpage
section{My section}label{sec1}
begin{figure}
    centeringHuge Figure
    caption{Bla bla.}
    label{fig1}
end{figure}
pref{fig1}qquadpref{sec1}
(cref{fig1})qquad(cref{sec1} : textit{nameref{sec1}})% desired behaviour

clearpage
pref{fig1}qquadpref{sec1}

clearpage
pref{fig1}qquadpref{sec1}
end{document}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP