[Open-graphics] Entirely rewritten LaTeX timing diagram... um... thing

Timothy Miller theosib at gmail.com
Mon Dec 25 02:20:03 EST 2006


It's 2AM.  What do you expect?

Anyhow, here it is.  It handles multiple lines, and I've even started
on the vector-drawing thing that you need to draw causal relationships
(although without an arrow head yet).

\newcount\tmgcellwidth
\newcount\tmgcellhalfwidth
\newcount\tmgcellquarterwidth
\newcount\tmgcellheight
\newcount\tmgcellhalfheight
\newcount\tmglineskip
\newcount\tmghsxa
\newcount\tmghsya
\newcount\tmghsxb
\newcount\tmghsyb
\newcount\tmghsxc
\newcount\tmghsyc
\newcount\tmgvty
\newcount\tmgvtdy
\newcount\tmgx
\newcount\tmgy
\newcount\tmgallh
\newcount\tmgallw
\newcount\tmglt
\newcount\tmglb
\newcount\tmghzx
\newcount\tmghzy
\newcount\tmgloopa
\newcount\tmgloopb
\newcount\tmgtmp
\newcount\markonex
\newcount\markoney
\newcount\marktwox
\newcount\marktwoy
\newcount\markthreex
\newcount\markthreey
\newcount\markfourx
\newcount\markfoury
\tmgcellwidth=8
\tmgcellhalfwidth=4
\tmgcellquarterwidth=2
\tmgcellheight=12
\tmgcellhalfheight=6
\tmglineskip=4
\newcommand{\settmgcellheight}[1]{%
    \tmgcellheight=#1%
    \tmgcellhalfheight=#1%
    \divide\tmgcellhalfheight 2}
\newcommand{\settmgcellwidth}[1]{%
    \tmgcellwidth=#1%
    \tmgcellhalfheight=#1%
    \divide\tmgcellhalfheight 2%
    \tmgcellquarterheight=#1%
    \divide\tmgcellquarterheight 4}
% Params:{width}{height}{commands}
\newcommand{\timing}[3]{
\begingroup%
\tmgx=0%
\tmgallh=\tmgcellheight%
\advance\tmgallh \tmglineskip%
\multiply\tmgallh #2%
\advance\tmgallh -\tmglineskip%
\tmgy=\tmgallh%
\advance\tmgy -\tmgcellheight%
\tmgallw=#1%
\multiply\tmgallw \tmgcellwidth%
\tmglt=-1%
\tmglb=-1%
%\catcode`\^^M=13%
\catcode`\\=13%
%\def^^M{%
%    \tmgx=0%
%    \tmglt=-1%
%    \tmglb=-1%
%    \advance\tmgy -\tmgcellheight%
%    \advance\tmgy -\tmglineskip}%
%}%
\def\\{%
    \tmgx=0%
    \tmglt=-1%
    \tmglb=-1%
    \advance\tmgy -\tmgcellheight%
    \advance\tmgy -\tmglineskip}%
\providecommand{\halfslope}{}%
\renewcommand{\halfslope}[2]{%
    \tmghsxa=\tmgx%
    \tmghsya=\tmgy%
    \advance\tmghsya ##1%
    \tmghsxc=\tmgx%
    \advance\tmghsxc \tmgcellhalfwidth%
    \tmghsyc=\tmgy%
    \advance\tmghsyc ##2%
    \tmghsxb=\tmgx%
    \advance\tmghsxb \tmgcellquarterwidth%
    \tmghsyb=\tmghsya%
    \advance\tmghsyb \tmghsyc%
    \divide\tmghsyb 2%
    \qbezier(\tmghsxa,\tmghsya)(\tmghsxb,\tmghsyb)%
        (\tmghsxc,\tmghsyc)}%
\providecommand{\vert}{}%
\renewcommand{\vert}[2]{%
    \tmgvty=##1%
    \advance\tmgvty \tmgy%
    \ifthenelse{##1 < ##2}{
        \tmgvtdy=##2%
        \advance\tmgvtdy -##1%
        \put(\tmgx,\tmgvty){\line(0,1){\tmgvtdy}}}{%
        \tmgvtdy=##1%
        \advance\tmgvtdy -##2%
        \put(\tmgx,\tmgvty){\line(0,-1){\tmgvtdy}}}}%
\providecommand{\halfhoriz}{}%
\renewcommand{\halfhoriz}[1]{%
    \tmghzx=\tmgx%
    \advance\tmghzx \tmgcellwidth%
    \tmghzy=\tmgy%
    \advance\tmghzy ##1%
    \put(\tmghzx,\tmghzy){\line(-1,0){\tmgcellhalfwidth}}}%
\providecommand{\horiz}{}%
\renewcommand{\horiz}[1]{%
    \tmghzy=\tmgy%
    \advance\tmghzy ##1%
    \put(\tmgx,\tmghzy){\line(1,0){\tmgcellwidth}}}%
\providecommand{\slope}{}%
\renewcommand{\slope}[2]{%
    \ifthenelse{\tmglt<0}{\relax}{%
        \halfslope{\tmglt}{##1}%
        \halfslope{\tmglb}{##2}%
        \halfhoriz{##1}\halfhoriz{##2}\next}
    \tmglt=##1%
    \tmglb=##2}%
\providecommand{\jump}{}%
\renewcommand{\jump}[2]{%
    \ifthenelse{\tmglt<0}{\relax}{%
        \vert{\tmglt}{##1}%
        \vert{\tmglb}{##2}%
        \horiz{##1}\horiz{##2}\next%
        }%
    \tmglt=##1%
    \tmglb=##2}%
\providecommand{\flip}{}%
\renewcommand{\flip}{%
    \tmghzy=\tmglt%
    \tmglt=\tmglb%
    \tmglb=\tmghzy}%
\providecommand{\next}{}%
\renewcommand{\next}{\advance\tmgx \tmgcellwidth}%
\providecommand{\l}{}%
\renewcommand{\l}[1][2]{
    \tmgloopa=0%
    \whiledo{\tmgloopa<##1}{%
        \slope{0}{0}%
        \advance\tmgloopa 1}}%
\providecommand{\u}{}%
\renewcommand{\u}[1][2]{
    \tmgloopa=0%
    \whiledo{\tmgloopa<##1}{%
        \slope{\tmgcellheight}{\tmgcellheight}%
        \advance\tmgloopa 1}}%
\providecommand{\ul}{}%
\renewcommand{\ul}[1][2]{
    \tmgloopa=0%
    \whiledo{\tmgloopa<##1}{%
        \slope{0}{\tmgcellheight}%
        \advance\tmgloopa 1}}%
\providecommand{\z}{}%
\renewcommand{\z}[1][2]{
    \tmgloopa=0%
    \whiledo{\tmgloopa<##1}{%
        \slope{\tmgcellhalfheight}{\tmgcellhalfheight}%
        \advance\tmgloopa 1}}%
\providecommand{\x}{}%
\renewcommand{\x}[1][2]{%
    \tmgloopb=1%
    \whiledo{\tmgloopb < ##1}{%
    \ul[1]%
    \advance\tmgx -\tmgcellhalfwidth%
    \halfslope{0}{\tmgcellheight}%
    \advance\tmgx \tmgcellhalfwidth%
    \halfslope{0}{\tmgcellheight}%
    \advance\tmgloopb 1}%
    \ul[1]%
    \advance\tmgx -\tmgcellhalfwidth%
    \halfslope{0}{\tmgcellheight}%
    \advance\tmgx \tmgcellhalfwidth}%
\providecommand{\text}{}%
\renewcommand{\text}[1]{%
    \tmgloopa=\tmgx%
    \advance\tmgloopa \tmgcellwidth%
    \put(\tmgloopa,\tmgy){\makebox(\tmgallw,\tmgcellheight)[l]{##1}}}%
\providecommand{\label}{}%
\renewcommand{\label}[1]{%
    \put(\tmgx,\tmgy){\makebox(\tmgallw,\tmgcellheight)[l]{##1}}}%
\providecommand{\clock}{}%
\renewcommand{\clock}[1]{%
    \tmgloopa=0%
    \jump{0}{0}%
    \whiledo{\tmgloopa < ##1}{%
        \jump{0}{0}\jump{\tmgcellheight}{\tmgcellheight}%
        \advance\tmgloopa 1}}%
\providecommand{\skip}{}%
\renewcommand{\skip}[1][1]{%
    \tmgloopa=##1%
    \multiply\tmgloopa \tmgcellwidth%
    \advance\tmgx \tmgloopa}%
\providecommand{\mark}{}%
\renewcommand{\mark}[1]{%
    \ifthenelse{##1=1}{%
    \markonex=\tmgx%
    \markoney=\tmgy}{%
    \ifthenelse{##1=2}{%
    \marktwox=\tmgx%
    \marktwoy=\tmgy}{%
    \ifthenelse{##1=3}{%
    \markthreex=\tmgx%
    \markthreey=\tmgy}{%
    \ifthenelse{##1=4}{%
    \markfourx=\tmgx%
    \markfoury=\tmgy}{\relax}}}}}%
\providecommand{\markx}{}%
\renewcommand{\markx}[1]{%
    \ifthenelse{##1=1}{%
    \tmgtmp=\markonex}{%
    \ifthenelse{##1=2}{%
    \tmgtmp=\marktwox}{%
    \ifthenelse{##1=3}{%
    \tmgtmp=\markthreex}{%
    \ifthenelse{##1=4}{%
    \tmgtmp=\markfourx}{\tmgtmp=0}}}}}%
\providecommand{\marky}{}%
\renewcommand{\marky}[1]{%
    \ifthenelse{##1=1}{%
    \tmgtmp=\markoney}{%
    \ifthenelse{##1=2}{%
    \tmgtmp=\marktwoy}{%
    \ifthenelse{##1=3}{%
    \tmgtmp=\markthreey}{%
    \ifthenelse{##1=4}{%
    \tmgtmp=\markfoury}{\tmgtmp=0}}}}}%
\providecommand{\vec}{}%
\renewcommand{\vec}[2]{%
    \markx{##1} \tmghsxa=\tmgtmp%
    \marky{##1} \tmghsya=\tmgtmp%
    \markx{##2} \tmghsxc=\tmgtmp%
    \marky{##2} \tmghsyc=\tmgtmp%
    \advance\tmghsxa \tmgcellhalfwidth%
    \advance\tmghsya \tmgcellhalfheight%
    \advance\tmghsxc \tmgcellhalfwidth%
    \advance\tmghsyc \tmgcellhalfheight%
    \tmghsxb=\tmghsxa%
    \advance\tmghsxb \tmghsxc%
    \divide\tmghsxb 2%
    \tmghsyb=\tmghsya%
    \advance\tmghsyb \tmghsyc%
    \divide\tmghsyb 2%
    \qbezier(\tmghsxa,\tmghsya)(\tmghsxb,\tmghsyb)%
        (\tmghsxc,\tmghsyc)}%
\setlength{\unitlength}{1pt}%
\begin{picture}(\tmgallw,\tmgallh)%
#3%
\end{picture}\endgroup}


Try putting this into a document:

\timing{20}{2}{\label{f53}\mark{1}\skip\l\u\ul\flip\ul\\
\z\z\mark{2}\x[4]\z\text{YYyy}\clock{4}\vec{1}{2}}

\timing{20}{6}{\label{clock}\skip[3]\clock{4}\\
\label{f53}\skip[3]\l\u\ul\flip\ul\\
\label{ews}\skip[3]\z\z\x[4]\z\text{YYyy}\\
\label{fhd}\skip[3]\z[5]\flip\mark{2}\ul[4]\\
\label{fhd}\skip[3]\ul[4]\flip\mark{1}\ul[5]\vec{1}{2}\\
\label{fhd}\skip[3]\ul[1]\flip\ul[4]}

-- 
Timothy Miller
http://www.cse.ohio-state.edu/~millerti


More information about the Open-graphics mailing list