# How to change Pandoc's / hyperref's reference format?

\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


or

# A section {#a-section}


both into

\hyperdef{}{a-section}{\section{A section}}\label{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}
\end{document}


which unfortunately renders the link as

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}

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

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