Closed Witiko closed 1 month ago
Using env/⟨name⟩/{before,after} and cmd/⟨name⟩/before seems OK:
\documentclass{article}
\usepackage{markdown}
\begin{document}
\AddToHook{cmd/markdownRendererEmphasis/before}{emphasis: }
\AddToHook{env/markdown/before}{<markdown>}
\AddToHook{env/markdown/after}{</markdown>}
\begin{markdown}
foo _bar_ baz!
\end{markdown}
\end{document}
However, using env/⟨name⟩/after works only for renderers with a fixed number of arguments that are defined without currying.
For example, in the above example, if you explicitly defined the renderer emphasis
with the command \markdownSetup
or using \def
without currying, then you would be able to also use the hook cmd/markdownRendererEmphasis/after:
\documentclass{article}
\usepackage{markdown}
\markdownSetup{renderers={emphasis={\emph{#1}}}}
\begin{document}
\AddToHook{cmd/markdownRendererEmphasis/before}{<emphasis>}
\AddToHook{cmd/markdownRendererEmphasis/after}{</emphasis>}
\AddToHook{env/markdown/before}{<markdown>}
\AddToHook{env/markdown/after}{</markdown>}
\begin{markdown}
foo _bar_ baz!
\end{markdown}
\end{document}
However, the default renderer emphasis
uses currying and calls the renderer prototype emphasis
in a way that prevents the use of the hook cmd/markdownRendererEmphasis/after:
I will document this.
As previously discussed with @frankmittelbach in https://github.com/Witiko/markdown/issues/93, we won't necessarily define our own LaTeX hooks for the Markdown package. However, we should at least ensure that standard hooks such as {cmd,env}/⟨name⟩/{before,after} are properly invoked before and after the markdown environments, renderers, and renderer prototypes. This will allow LaTeX users to use hooks as an alternative to redefining and patching the renderers and renderer prototypes directly or through the
\markdownSetup
command.