My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic.
I'm writting a document with markdown syntax and converting it to LaTeX (and html) via pandoc. This document contains hyperlinks to some web sites. When I write in markdown:
See [this web](http://tex.stackexchange.com/)
It produces in TeX:
See \href{http://tex.stackexchange.com/}{this web}
I want to implement a version of \href
which, in addition to inserting a hyperlink in the pdf, it also makes a footnote containing the url, which is more useful for the printed version of the document. I did it as follows:
\let\oldhref=\href
\renewcommand{\href}[2]{\oldhref{#1}{#2}\footnote{\url{#1}}}
So far so good. It works as expected.
Now the problem is that pandoc also supports "internal references" to other sections in the document. If I have a section called Related work
, pandoc automatically generates a internal anchor name related-work
, so I can write in my markdown source:
# Related work
Blah blah
# Another section
See [section about related work](#related-work)
The above markdown is translated into:
\hyperdef{}{related-work}{\section{Related work}\label{related-work}}
Blah blah
\section{Another section}
See \href{\#related-work}{section about related work}.
Now my problems is that, with my redefinition of \href
this internal reference also produces a footnote, which clearly unncesary. The footnote only shows the text #related-work
, which is not useful for the reader, and in addition clicking ot the footnote text produces an error (while other footnotes which show urls work fine).
So, my question: how can I redefine \href
in such a way that:
- If the first char of its first argument is
#
(or is it\#
?), it behaves as the standard\href
(no footnote) - Else, it works as my redefinition (internal hyperlink plus footnote typeseting the destination url).