I am trying to defer processing of some latex code.
This works,
\documentclass[a4paper,final,11pt]{article}
\usepackage{hyperref}
\begin{document}
here comes a reference
\href{http://www.example.com/doc#list}{doc}
\end{document}
but I need to move up the importing of codeToBeDeferred
(containing the \href
), and render/process it in the same place. So I changed it to this.
\documentclass[a4paper,final,11pt]{article}
\usepackage{hyperref}
\newcommand{\deferredCode}{
\href{http://www.example.com/doc#list}{doc}
}
\begin{document}
here comes a reference
\deferredCode
\end{document}
This works, except for the #
in the \href
, note the #
was not a problem in the original code.
side note: I am reading the code early and deferring processing because the code is merged together by a preprocessor, the preprocessor needs to process the deferred code early, but latex needs to do it latter.
Well all this works, except when the codeToBeDeferred
has a # in it. \newcommand
does not like it. If I put a \
before the #
it fixes it, however I do not want to do this: there are a lot of historic versions of this code, I don't want to have to remember when I write new code. The code is valid latex when not part of a \newcommand
How can I allow a #
in a \newcommand
?
or
How else can I defer the processing of this block of code?
The #
is in a \href
in the deferred code, it works outside of a \newcommand
.
What I am hoping for, is a wrapper to stop the #
being a problem. If the #
is only a problem when in a \newcommand
then this may be possible.
%somePreambleCode
\newcommand{\deferredCode}{
\wrapper{
\href{http://www.example.com/doc#list}{doc}
}
}
%someOtherCode
\deferredCode
I know that I can escape the #
with a \
(changing it to \#
), but am hoping for another way.
I don't want to edit the code to be deferred. There is a choice of hundreds of them, I don't want them to be constrained by me doing this deferral trick to fix another problem.
#
as “text”? I think a more particular example would be great. – Manuel yesterday#
then you need\#
in anycase unrelated to\newcommand
\begin{document} a # b \end{document}
is an error you needa \# b
– David Carlisle yesterday#
character, however, this stands as a placeholder for the number of a specific argument. As the command\deferredcode
has no argument,LaTeX
will complain about a direct#
occuring somewhere inside the command, especially, if not followed by a number from 1 up to 9. – Christian Hupfer yesterday\noexpand
or\unexpanded
. Could you also explain in short why there are#
characters in the command body? – Christian Hupfer yesterday#1
, etc.? If so, you are probably looking for tex.stackexchange.com/questions/42463/… – Joseph Wright♦ yesterday