shicks / inlinedef Goto Github PK
View Code? Open in Web Editor NEWLaTeX inlinedef package
LaTeX inlinedef package
I'd like to conditionally define parts of a macro depending on whether the debug mode is on or not. So, assuming \newif\ifdebug
, I'd like to write
\Inline\def\macro{%
...
\ExpandIfT{debug}{debug code }%
...
}
With inlinedef, I'm almost there. I can define \ExpandIfT
(and its cousins \ExpandIfF
and \ExpandIfTF
not shown here), and then expand them manually using \MultiExpand
:
\def\ExpandIfT#1{%
\csname
\csname if#1\endcsname
@firstofone%
\else
@gobble%
\fi
\endcsname
}
\newif\ifdebug
\debugtrue
\Inline\def\macro{%
...
\MultiExpand{3}{\ExpandIfT{debug}{debug code }}%
...
}
However, being able to use \ExpandIf(T)(F)
directly has quite an appeal to me. I investigated inlinedef code a bit and it doesn't seem very hard to extend it to accept user defined keywords inside an \Inline
definition. I have drafted a patch makes this possible.
The idea is to define user commands in terms of \Expand
, or, more probably, \MultiExpand
. When a user keyword is encountered in the definition, it is expanded by the \UnsafeExpand
mechanism.
I hope you will consider accepting the extension into the package.
From @sasozivanovic, in reference to #1:
I also need this mechanism with \csdef
.
\expandafter\Inline\expandafter\def\csname macro\endcsname ...{...}
does not work, because \csname macro\endcsname
lets \macro
to \relax
and then \Inline
chokes on \meaning\macro
.
The workaround, which I believe would be beneficial anyway, could be to have a command (named something like) \InlineNoDef
, which would take a single argument, do its expansion magic, and execute it. This would readily support \csdef
, though without redefinitions, but I must selfishly admit I'm not interested in those at this time.
Again, I attach the relevant definition which simply skips over the gruesome job of parsing the macro prefixes and parameters ;-)
I guess my example of usage also answers a question from the documentation: no, \Inline
should not be \outer
.
\def\forest@newarray@#1{%
...
\InlineNoDef{\csdef{#1bottompop}##1{% ##1 = receiving cs
\Expand{\csname#1ifempty\endcsname}{%
\forest@array@empty@error{#1}%
}{%
\letcs##1{#1\the\Expand{\csname#1M\endcsname}}%
\ExpandIfT{forest@temp}\global
\advance\Expand{\csname#1M\endcsname 1}%
}%
}}%
...
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.