From 1478f7b073efd3aee384afa07bf3f09f5d759bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Thu, 27 Oct 2022 21:03:10 +0200 Subject: [PATCH] Add `\markdownEscape` macro --- markdown.dtx | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/markdown.dtx b/markdown.dtx index 8dabdf11a..d279106ab 100644 --- a/markdown.dtx +++ b/markdown.dtx @@ -8955,8 +8955,8 @@ pdftex --shell-escape document.tex % %### Typesetting Markdown {#textypesetting} % -% The interface exposes the \mdef{markdownBegin}, \mdef{markdownEnd}, and -% \mdef{markdownInput} macros. +% The interface exposes the \mdef{markdownBegin}, \mdef{markdownEnd}, +% \mdef{markdownInput}, and \mdef{markdownEscape} macros. % % The \mref{markdownBegin} macro marks the beginning of a markdown document % fragment and the \mref{markdownEnd} macro marks its end. @@ -9014,9 +9014,9 @@ pdftex --shell-escape document.tex % \bye % ``````` % -% The \mref{markdownInput} macro accepts a single parameter containing the -% filename of a markdown document and expands to the result of the conversion -% of the input markdown document to plain \TeX{}. +% The \mref{markdownInput} macro accepts a single parameter with the filename +% of a markdown document and expands to the result of the conversion of the +% input markdown document to plain \TeX{}. % % \end{markdown} % \begin{macrocode} @@ -9037,6 +9037,19 @@ pdftex --shell-escape document.tex % \bye % ``````` % +% The \mref{markdownEscape} macro accepts a single parameter with the filename +% of a \TeX{} document and executes the \TeX{} document in the middle of a +% markdown document fragment. Unlike the `\input` built-in of \TeX, +% \mref{markdownEscape} guarantees that the standard catcode regime of your +% \TeX{} format will be used. +% +% \end{markdown} +% \begin{macrocode} +\let\markdownEscape\relax +% \end{macrocode} +% \par +% \begin{markdown} +% %### Options {#texoptions} % % The plain \TeX{} options are represented by \TeX{} commands. Some of them map @@ -25206,6 +25219,22 @@ end }% |endgroup % \end{macrocode} +% \par +% \begin{markdown} +% The \mref{markdownEscape} macro resets the category codes of the percent sign +% and the hash sign back to comment and parameter, respectively, before using +% the `\input` built-in of \TeX{} to execute a \TeX{} document in the middle of +% a markdown document fragment. +% \end{markdown} +% \begin{macrocode} +\gdef\markdownEscape#1{% + \catcode`\%=14\relax + \catcode`\#=6\relax + \input #1\relax + \catcode`\%=12\relax + \catcode`\#=12\relax +}% +% \end{macrocode} % \iffalse % %<*latex> @@ -25940,11 +25969,7 @@ end \end{table}% }{% \ifthenelse{\equal{#1}{tex}}{% - \catcode`\%=14\relax - \catcode`\#=6\relax - \input #3\relax - \catcode`\%=12\relax - \catcode`\#=12\relax + \markdownEscape{#3}% }{% \markdownInput{#3}% }%