2

\frontmatter

As described in a related question, pandoc turns Markdown links such as

[TeX.SE](https://tex.stackexchange.com/)

into

\href{https://tex.stackexchange.com/}{TeX.SE}

However, in contrast to what is stated there, the current version of pandoc turns

# A section
Linking to [A section]

or

# A section {#a-section}
Linking to [A section](a-section)

both into

\hyperdef{}{a-section}{\section{A section}}\label{a-section}
Linking to \hyperref[a-section]{A section}

i.e. it uses \hyperref and not \href.


\mainmatter

I would like to change the formatting of the reference pandoc creates, preferably via my custom class custom.cls I tell pandoc to use (via documentclass: custom in the Markdown-document's YAML-Header). So I tried this:

\documentclass{scrartcl}

\usepackage{hyperref}

\let\orghyperref\hyperref
\renewcommand*{\hyperref}[2]{\orghyperref[#1]{\texttt{#2}}}

\begin{document}
\hyperdef{}{a-section}{\section{A section}}\label{a-section}
Linking to \hyperref[a-section]{A section}
\end{document}

which unfortunately renders the link as

Linking to a-section]A section

instead. What went wrong?

1 Answers1

2

Since the referred-to label is passed in brackets [] instead of braces {}, the command redefinition must provide some kind of default, i.e. add another pair of brackets behind the [2]:

\documentclass{scrartcl}

\usepackage{hyperref}

\let\orghyperref\hyperref  %↓↓
\renewcommand*{\hyperref}[2][]{\orghyperref[#1]{\texttt{#2}}}
%                           ↑↑ that's all that changed

\begin{document}
\hyperdef{}{a-section}{\section{A section}}\label{a-section}
Linking to \hyperref[a-section]{A section}
\end{document}

I am however quite certain that this will break should the second version of that command,

\hyperref{URL}{category}{name}{text}

ever be used, but I really haven't bothered enough with \@ifnextchar to properly treat that case...