I may be reinventing the wheel, but I had some fun doing this, lame as
it may be. What I wanted to do was type timing diagrams into LaTeX
documents and be able to add the diagrams as characters into text or
tables or whatever.
Here's the macro:
\usepackage{ifthen}
\newcommand{\timing}[2]{
\begingroup%
\count0=0%
\providecommand{\x}{}%
\renewcommand{\x}{%
\put(\count0,0){\line(1,4){0.5}}%
\put(\count0,2){\line(1,-4){0.5}}%
\advance\count0 1%
\put(\count0,2){\line(-1,0){0.5}}%
\put(\count0,0){\line(-1,0){0.5}}}%
\providecommand{\u}{}%
\renewcommand{\u}[1][1]{%
\put(\count0,2){\line(1,0){##1}}%
\advance\count0 ##1}%
\providecommand{\l}{}%
\renewcommand{\l}[1][1]{%
\put(\count0,0){\line(1,0){##1}}%
\advance\count0 ##1}%
\providecommand{\z}{}%
\renewcommand{\z}[1][1]{%
\put(\count0,1){\line(1,0){##1}}%
\advance\count0 ##1}%
\providecommand{\ul}{}%
\renewcommand{\ul}[1][1]{%
\put(\count0,2){\line(1,0){##1}}%
\put(\count0,0){\line(1,0){##1}}%
\advance\count0 ##1}%
\providecommand{\ulx}{}%
\renewcommand{\ulx}[1][1]{%
\count1=0%
\put(\count0,2){\line(-1,-4){0.5}}%
\whiledo{\count1 < ##1}{%
\put(\count0,2){\line(1,0){1}}%
\put(\count0,0){\line(1,0){1}}%
\put(\count0,0){\line(1,4){0.5}}%
\advance\count0 1%
\put(\count0,2){\line(-1,-4){0.5}}%
\advance\count1 1}}%
\providecommand{\t}{}%
\renewcommand{\t}[1]{%
\put(\count0,0){\makebox(10,2)[l]{##1}}}%
\providecommand{\s}{}%
\renewcommand{\s}{%
\put(\count0,0){\line(1,4){0.5}}%
\advance\count0 1%
\put(\count0,2){\line(-1,0){0.5}}}%
\providecommand{\lz}{}%
\renewcommand{\lz}{%
\put(\count0,0){\line(0,1){1}}%
\advance\count0 1%
\put(\count0,1){\line(-1,0){1}}}%
\providecommand{\zl}{}%
\renewcommand{\zl}{%
\put(\count0,1){\line(0,-1){1}}%
\advance\count0 1%
\put(\count0,0){\line(-1,0){1}}}%
\providecommand{\g}{}%
\renewcommand{\g}[1][1]{%
\advance\count0 ##1}%
\providecommand{\b}{}%
\renewcommand{\b}{%
\put(\count0,2){\line(1,-4){0.5}}%
\advance\count0 1%
\put(\count0,0){\line(-1,0){0.5}}}%
\providecommand{\uz}{}%
\renewcommand{\uz}{%
\put(\count0,2){\line(0,-1){1}}%
\advance\count0 1%
\put(\count0,1){\line(-1,0){1}}}%
\providecommand{\zu}{}%
\renewcommand{\zu}{%
\put(\count0,1){\line(0,-1){1}}%
\advance\count0 1%
\put(\count0,0){\line(-1,0){1}}}%
\providecommand{\v}{}%
\renewcommand{\v}{%
\put(\count0,0){\line(0,1){2}}}%
\providecommand{\clock}{}%
\renewcommand{\clock}[2][1]{%
\count1=0%
\whiledo{\count1 < ##2}{\l[##1]\v\u[##1]\v\advance\count1 1}%
\l[##1]}%
\setlength{\unitlength}{6pt}%
\begin{picture}(#1,2)%
#2%
\end{picture}\endgroup}
Then in the body of the document, you can do things like this:
\begin{tabular}{l|l|}
Clock & \timing{13}{\clock{4}} \\
Tim & \timing{13}{\u\b\t{tim}\l[3]\s\u} \\
Them & \timing{13}{\ul\x\t{0xFFFF}\ul[10]\x} \\
Argh & \timing{13}{\l\lz\z[3]\zl\s\uz\z[3]\zu} \\
ulx & \timing{13}{\ul\ulx\x\t{3}\ul[2]\x\ulx[2]\x\t{4}\ul[3]\x}
\end{tabular}
So, the sequence {\x\t{signal}\ul[4]} will yield a transition on a
multi-line bus and an over/under bar of 4 half periods labeled
'signal'.
As it is, it really needs refinement, but what I'd REALLY like to be
able to do is something like this instead (for the ulx one above):
\timing{13}{=#x"3"=[2]x#[2]x"4"=[3]x}
That would require TeX way too deep for my level of knowledge, but it
would make it a lot more compact, and, choosing the right symbols,
more readable. And taking it a step further, I'd like to make it
multi-line and add vectors so that you can also draw arrows from one
line to another to show causal relationships. Unfortunately, the
picture environment is painfully restrictive in what you can do with
slanted lines. Perhaps something can be done with qbezier, but I
don't fully understand how to do math and variables in TeX.
--
Timothy Miller
http://www.cse.ohio-state.edu/~millerti
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)