Skip to content

Instantly share code, notes, and snippets.

@sharmaeklavya2
Created January 31, 2026 08:31
Show Gist options
  • Select an option

  • Save sharmaeklavya2/9ad36e402f8594158033bed8e9820725 to your computer and use it in GitHub Desktop.

Select an option

Save sharmaeklavya2/9ad36e402f8594158033bed8e9820725 to your computer and use it in GitHub Desktop.
extref.tex: useful for mocking and appendectomies
% syntax: \extRefReg{label}{type}{id}
\newcommand*{\extRefReg}[3]{%
\expandafter\def\csname extref-type:#1\endcsname{#2}%
\expandafter\def\csname extref-id:#1\endcsname{#3}%
}
\newif\ifUseExtRef
\let\extRefOn\UseExtReftrue
\let\extRefOff\UseExtReffalse
\newcommand*{\extRef}[1]{%
\ifUseExtRef
\ifcsname extref-id:#1\endcsname
\csname extref-id:#1\endcsname
\else
\PackageError{extref}{unregistered ref: #1}{}
\fi
\else
\ref{#1}%
\fi
}
\newcommand*{\extCref}[1]{%
\ifUseExtRef
\ifcsname extref-id:#1\endcsname
\csname extref-type:#1\endcsname~\csname extref-id:#1\endcsname
\else
\PackageError{extref}{unregistered cref: #1}{}
\fi
\else
\cref{#1}%
\fi
}
\newcommand*{\extCrefCraw}[2]{\extCref{#1}\ifUseExtRef\ #2 \extRefSource\fi}
\newcommand*{\extCrefCof}[1]{\extCrefCraw{#1}{of}}
\newcommand*{\extCrefCin}[1]{\extCrefCraw{#1}{in}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment