I use the markdown-package in combination with pdfLaTeX.

\documentclass{article}

\usepackage[
blankBeforeBlockquote,
blankBeforeCodeFence,
codeSpans,
citations,
definitionLists,
fencedCode,
hybrid,
underscores,
inlineFootnotes,
hashEnumerators ]{markdown}

\usepackage{hyperref}

\begin{document}
\begin{markdown}

Here's a link to [a website](https://developer.android.com/training/testing/fundamentals.html#testing-pyramid).

\end{markdown}
\end{document}


If I compile the above code, I get following error message.

Illegal parameter number in definition of \Hy@tempa.

I presume this has something to do with macros, because macro arguments are led by #.

I also tried the following tip the complier gave me. This works for compilation, but than the link is broken in the pdf ...html#%23testin....

You meant to type ## instead of #, right? Or maybe a } was forgotten somewhere earlier, and things are all screwed up? I'm going to assume that you meant ##.

The markdown-package generates a tmp file, that looks like this, maybe it helps for answering:

Here's a link to \markdownRendererLink{a website}{https://developer.android.com/training/testing/fundamentals.html#testing-pyramid}{https://developer.android.com/training/testing/fundamentals.html#testing-pyramid}{}.\relax


I am not that deep into macros, so I am not shure, if there can something be done.

• Untested: maybe \# instead of # works here. – Marijn Mar 6 '18 at 14:26
• @Marijn sorry, but \# doesn't work for me – addyi Mar 7 '18 at 8:39

Imho the only thing that works is to temporarly change the catcode of #:

\documentclass{article}

\usepackage[
blankBeforeBlockquote,
blankBeforeCodeFence,
codeSpans,
citations,
definitionLists,
fencedCode,
hybrid,
underscores,
inlineFootnotes,
hashEnumerators ]{markdown}

\usepackage{hyperref}

\begin{document}
\begin{markdown}

Here's a link to {\catcode\#=12 [a website](https://developer.android.com/training/testing/fundamentals.html#testing-pyramid).}

\end{markdown}
\end{document}

• I did need to change the \catcode command to {\catcode35=12 [a website](url).} but else it worked fine – addyi Mar 7 '18 at 7:54
• The alternative linking methode in markdown works also like this: {\catcode35=12 [Linktext][refToLink]} and [refToLink]: https://... – addyi Mar 7 '18 at 7:58
• Not sure why you "need" to use \catcode35, but it is the same --  \#  is only a different way to write 35 which avoids that one has to remember the number. – Ulrike Fischer Mar 7 '18 at 8:22
• It is a special character in markdown and therefor I got another problem. A mix of Markdown and LaTeX is maybe a bit overkill, but I like the simplicity of Markdown and the beautiful PDF Document I get from LaTeX. – addyi Mar 7 '18 at 8:30
• There is an alternative package-specific solution that involves redefining the \markdownRendererLink TeX command and that does not require you to litter your markdown markup with macros. I will post the solution later, but you can see the technical documentation for yourself in the meantime [1], [2]. – Witiko Mar 7 '18 at 11:20

As discussed in the comment section of Ulrike Fischer's answer, you can redefine \markdownRendererLink so that it changes the category code of the hash sign (#) before the parameters have been consumed. This keeps the logic separate from the markdown markup:

\documentclass{article}
\usepackage{markdown}
\begingroup
\catcode\#=12
\def\next##1##2##3##4{%

\markdownRendererLinkPrototype` is the default command for rendering hyperlinks.