
% edrxdiagflags.tex: a hack to let us create variations of a diagram
% in which certain arrows are omitted.
% Edrx, 2006jul17
% This is experimental stuff!
Edrx, 2005jun25

% (find-dn4file "examples/")
% (find-dn4 "examples/edrxdnt.tex" "defded")

% (find-texbookpage (+ 11 203))
%
\def\setdiagflagto#1#2{\expandafter\def\csname diagflag-#2\endcsname{#1}}
\def\diagflagy{y}
\def\diagflags#1{
  \def\Y##1{\setdiagflagto{y}{##1}}
  \def\N##1{\setdiagflagto{n}{##1}}
  #1
}

% (find-texbookfile "texbook.tex" "|\\ifundefined#1|")
% (find-texbookfile "texbook.tex" "test if tokens agree")
% (find-texbookpage (+ 11 40)  "Exercise 7.7: define \\ifundefined")
% (find-texbookpage (+ 11 308) "Exercise 7.7: answer")
% (find-texbookpage (+ 11 210) "\\ifx: test if tokens agree")
%
\def\ifdiagflagundefined#1{\expandafter\ifx\csname diagflag-#1\endcsname\relax}
\def\ifdiagflagy#1{\expandafter\ifx\csname diagflag-#1\endcsname\diagflagy}
\def\ifdiagflag#1#2{\ifdiagflagundefined{#1}
    \errmessage{UNDEFINED DIAGFLAG: #1}
  \else
    \ifdiagflagy{#1}#2\fi
  \fi
}

% How these macros are invoked:
%   \setdiagflagto{y}{FOO}     % sets diagflag FOO to ``yes''
%   \setdiagflagto{n}{FOO}     % sets diagflag FOO to ``no''
%   \diagflags{\Y{FOO} \N{BAR}}% sets diagflag FOO to ``yes'' and BAR to ``no''
%   \ifdiagflagundefined{FOO}{diagflag FOO is undefined}
%   \ifdiagflagy{FOO}{diagflag FOO is ``yes''}
%   \ifdiagflag{FOO}{run this if diagflag FOO is ``yes'', error if undefined}
% Only "\diagflags" is meant to be invoked by the user; the dednat4
% construct ".flag= FOO" tells dednat4 to wrap the current arrow -
% i.e., the call to \morphism that it becomes in the .dnt file -
% inside a "\ifdiagflag{FOO}{...}", but users don't see it.

% (find-dn4file "dednat4.lua")
% (find-dn4file "dednat4.lua" "if arrow.special")
% (find-dn4file "dednat4.lua" ".plabel=")

%L arrowspecial_diagflag = function (arrow)
%L     return format("\\ifdiagflag{%s}{%s}", arrow.flag,
%L         arrowtoTeX(arrow, "ignorespecial")
%L   end
%L forths[".flag="] = function ()
%L     ds[1].flag = getword()
%L     ds[1].special = arrowspecial_diagflag
%L   end




% Local Variables:
% coding:               raw-text-unix
% ee-delimiter-percent: "\n%\n"
% ee-anchor-format:     "«%s»"
% End:
