Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that standard LaTeX hooks work as expected #464

Closed
Witiko opened this issue Jul 21, 2024 · 1 comment · Fixed by #507
Closed

Check that standard LaTeX hooks work as expected #464

Witiko opened this issue Jul 21, 2024 · 1 comment · Fixed by #507
Labels
documentation Related the technical documentation, the user manual, and the README files latex Related to the LaTeX interface and implementation tug 2024 Related to the TUG 2024 conference
Milestone

Comments

@Witiko
Copy link
Owner

Witiko commented Jul 21, 2024

As previously discussed with @FrankMittelbach in #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.

@Witiko Witiko added latex Related to the LaTeX interface and implementation technical debt Related to code smells and refactoring tug 2024 Related to the TUG 2024 conference labels Jul 21, 2024
@Witiko Witiko added this to the 3.7.1 milestone Jul 21, 2024
@Witiko Witiko modified the milestones: 3.7.1, 3.8.0 Aug 30, 2024
@Witiko
Copy link
Owner Author

Witiko commented Oct 2, 2024

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}

image

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}

image

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:

markdown/markdown.dtx

Lines 15751 to 15752 in a494c09

\def\markdownRendererEmphasis{%
\markdownRendererEmphasisPrototype}%

I will document this.

@Witiko Witiko added documentation Related the technical documentation, the user manual, and the README files and removed technical debt Related to code smells and refactoring labels Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related the technical documentation, the user manual, and the README files latex Related to the LaTeX interface and implementation tug 2024 Related to the TUG 2024 conference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant