13 Jun 15:08
Macros with optional parameters in paths
Robert Homann <rhomann <at> techfak.uni-bielefeld.de>
2007-06-13 13:08:59 GMT
2007-06-13 13:08:59 GMT
Hi!
Currently, I am trying to write some macros for drawing parse trees, based on
TikZ. Each of these macros corresponds to an operator, and they are designed to
embed each other in order to generate nodes on a path. So, inside a tikzpicture
environment, I start drawing with a \path command, followed by some of my
macros that emit "node" and "child" commands, and stop with a semicolon.
This works all well, but now I would like my macros to accept optional
parameters. Unfortunately, it seems like \path is choking on the \@ifnextchar
command that is used to handle the []-brackets.
Could someone please take a look at the artificial example below that
illustrates my problem?
---
\listfiles
\documentclass[11pt,a4paper]{scrartcl}
\usepackage{tikz}
\makeatletter
\def\Works{\@ifnextchar[{\@Works}{\@Works[]}}
\def\@Works[#1]#2#3#4{\path[draw] (0,#2) node[draw] {#3} -- (2,#2) node[draw#1] {#4};}
\def\Fails{\@ifnextchar[{\@Fails}{\@Fails[]}}
\def\@Fails[#1]#2#3#4{(0,#2) node[draw] {#3} -- (2,#2) node[draw#1] {#4}}
\makeatother
(Continue reading)
RSS Feed