programming: doifdefined & friends
While I can't cope with counters, I'm trying other stuff that I don't understand: How must I use \doifdefined & friends? Consider this snippet: ----- \starttext \def\myvar{JAJAJA} \input tufte \doifdefined{\myvar}{\par bla \myvar blub\par} \input tufte \stoptext ----- I'd guess it would print "bla JAJAJAblub" between the two Tufte texts and don't if I comment \def\myvar. But I guess wrongly: It does nothing in this case, and complains about undefined \myvar in the latter. But if I really want to check if something is defined before I try to use it, how must I write it? (Expansion magic?) Greetlings from Lake Constance! Hraban --- http://www.fiee.net/texnique/ http://contextgarden.net http://www.cacert.org (I'm an assurer)
Am 2006-10-05 um 02:42 schrieb Henning Hraban Ramm:
----- \starttext
\def\myvar{JAJAJA}
\input tufte \doifdefined{\myvar}{\par bla \myvar blub\par} \input tufte
\stoptext -----
Sorry for bothering you, I found it myself: I must leave out the backslash in the condition. But so I'm still stuck with this snippet from the LilyPond module, where Christopher used a lot of catcode trickery: ----- /doifdefined{lily!fontname}/bgroup \layout {/string^^J \override Staff.TimeSignature #'font-name = #/lily!fontname/string^^J \override Staff.MultiMeasureRestText #'font-name = #/lily!fontname/ string^^J \override Score.LyricText #'font-name = #/lily!fontname/string^^J \override ChordNames.ChordName #'font-name = #/lily!fontname/string^^J }/string^^J /egroup ----- gives: ! Undefined control sequence. \lily!prefix ...ure #'font-name = #\lily!fontname \string \override Staff.... <argument> ...nd-\the \lily!figures ]\lily!prefix \lily!hash (set- global-sta... \expanded ...\long \xdef \@@expanded {\noexpand #1 }\@@expanded \dodostartlilypond ...e \lily!fragmentsuffix \fi } \endbuffer \par \def \LP {... l.43 \stoplilypond ----- I'm trying to introduce a "fontname" setting in \setuplilypond that should generate the \layout{...} block in the LilyPond file if used and nothing if not. I know how to do that with numbers and yes/no settings, because there are some samples in the module, but unfortunately no string settings - and I don't understand the samples that I found in the ConTeXt sources either. Greetlings from Lake Constance! Hraban --- http://www.fiee.net/texnique/ http://contextgarden.net http://www.cacert.org (I'm an assurer)
Sorry, last one for tonight. Just forget my question - it wouldn't work this way anyway. - the \doif stuff got printed in the LilyPond file instead of executed - my LilyPond font settings can't work at that place, because \overrides must stand in their appropriate score section :-( Greetlings from Lake Constance! Hraban --- http://www.fiee.net/texnique/ http://contextgarden.net http://www.cacert.org (I'm an assurer)
On Thu, 5 Oct 2006, Henning Hraban Ramm wrote:
While I can't cope with counters, I'm trying other stuff that I don't understand: How must I use \doifdefined & friends?
Consider this snippet:
----- \starttext
\def\myvar{JAJAJA}
\input tufte \doifdefined{\myvar}{\par bla \myvar blub\par} \input tufte
\stoptext -----
I'd guess it would print "bla JAJAJAblub" between the two Tufte texts and don't if I comment \def\myvar.
But I guess wrongly: It does nothing in this case, and complains about undefined \myvar in the latter.
That is because \doifdefined is for strings. It adds a \csname ... \endcsname around its first argument.
But if I really want to check if something is defined before I try to use it, how must I write it?
The plain tex way \ifx\myvar\undefined %Nothing here \else \par bla \myvar blub\par \fi or the context way (for strings) \doifdefined{myvar}{\par bla \myvar blub\par} Aditya
participants (2)
-
Aditya Mahajan
-
Henning Hraban Ramm