* programming: doifdefined & friends
@ 2006-10-05 0:42 Henning Hraban Ramm
2006-10-05 0:56 ` Henning Hraban Ramm
2006-10-05 4:04 ` Aditya Mahajan
0 siblings, 2 replies; 4+ messages in thread
From: Henning Hraban Ramm @ 2006-10-05 0:42 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: programming: doifdefined & friends
2006-10-05 0:42 programming: doifdefined & friends Henning Hraban Ramm
@ 2006-10-05 0:56 ` Henning Hraban Ramm
2006-10-05 1:15 ` Henning Hraban Ramm
2006-10-05 4:04 ` Aditya Mahajan
1 sibling, 1 reply; 4+ messages in thread
From: Henning Hraban Ramm @ 2006-10-05 0:56 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: programming: doifdefined & friends
2006-10-05 0:56 ` Henning Hraban Ramm
@ 2006-10-05 1:15 ` Henning Hraban Ramm
0 siblings, 0 replies; 4+ messages in thread
From: Henning Hraban Ramm @ 2006-10-05 1:15 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: programming: doifdefined & friends
2006-10-05 0:42 programming: doifdefined & friends Henning Hraban Ramm
2006-10-05 0:56 ` Henning Hraban Ramm
@ 2006-10-05 4:04 ` Aditya Mahajan
1 sibling, 0 replies; 4+ messages in thread
From: Aditya Mahajan @ 2006-10-05 4:04 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-10-05 4:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-05 0:42 programming: doifdefined & friends Henning Hraban Ramm
2006-10-05 0:56 ` Henning Hraban Ramm
2006-10-05 1:15 ` Henning Hraban Ramm
2006-10-05 4:04 ` Aditya Mahajan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).