# Is it possible to define abbreviations for coding?

I am using the tikz-timing package to create a timeline since chronosys and chronology wouldn't cooperate and were too limited and archaic-looking to suit my purposes, and moderntimeline unfortunately was unable to display in a horizontal linear format. (The timeline I'm trying to create is rather complex, and the timeline package selection is extremely limited.)

Everything is working fairly nicely, considering that I have just recently taken up LaTeX (after some limited experience with Lilypond) to create this timeline, except for the fact that typing [white, timing/D/background/.style={fill=orange}] takes up a ridiculous amount of space (and time), which is very inconvenient and makes the code look super messy.

I've tried using \newcommand (I've heard \def is basically just an inferior version of it), but so far the compiler doesn't like me using it that way because I'm not defining an actual command, just a substitution.

\newcommand{\efill}[1]{timing/D/background/.style={fill=#1}}


thinking this would allow me to type [\efill {blue}] to set the fill to blue. Since this was an abbreviation and not a command, it didn't work the way I had intended it to.

The ideal solution would allow the definition of character-to-color synonyms (so instead of typing the whole color name, I could just type the single-character name), and the definition of a custom enclosure notation (eg {{ob}} would expand during compilation to [orange, timing/D/background/.style={fill=blue}].

How can I achieve this?

Here is my newbie attempt at an MWE:

\documentclass{article}
\usepackage{tikz, tikz-timing}

\begin{document}
\Huge
\begin{tikztimingtable}
{\LARGE{Benjy}}  & [blue, timing/D/background/.style={fill=none}]DDDD;[orange,timing/D/background/.style={fill=green}]DDDD  \\

\begin{extracode}
{\begin{Large}Character\end{Large}}
{\begin{LARGE}\textbf{Events}\end{LARGE}}
\tablerules
\fulltablegrid
\end{extracode}
\end{tikztimingtable}
\end{document}


I'm not sure if I tagged this correctly, so feel free to add/remove tags.

• Can you please add a minimal working example (MWE)? – egreg Jan 24 '14 at 16:53
• using the command as \efill blue will recognize only the "b" as the argument of \efill. before giving up, try \efill{blue} to include the whole word in the argument. – barbara beeton Jan 24 '14 at 17:20
• @barbarabeeton Oh right... Thank you for pointing that out. I figured had that out in the actual code, but failed to type it with the fix here... :\ Sorry! Will fix immediately! – ksoo Jan 24 '14 at 17:24
• Use commands like \LARGE like {\LARGE <text>}: they are switches, not commands that take arguments. And you are likely to run into problems if you jam all kinds of different fontsize declarations (or 'switches') in the same paragraph. – jon Jan 24 '14 at 20:15
• @AsianSquirrel I answered your question about a month ago and you did neither accept, nor comment on my answer. Please let me know, if it fits your needs, so I can adjust it accordingly. – Henri Menke Mar 22 '14 at 12:32

I hope, I got your question right.

I defined a new TikZ style efill, which takes two arguments.

• #1 is the draw color
• #2 is the fill color

Then one can use the style like

efill={draw color}{fill color}


To achieve the requested abbreviations b -> blue, etc. I used \colorlet like in

\colorlet{b}{blue}


# Implementation

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz,tikz-timing}
\colorlet{b}{blue}
\colorlet{o}{orange}
\colorlet{g}{green}
\tikzset{
efill/.style n args={2}{
#1,timing/D/background/.style={fill=#2}
}
}
\begin{document}
\Huge
\begin{tikztimingtable}
{\LARGE Benjy}  & [efill={b}{none}]DDDD;[efill={o}{g}]DDDD  \\
\begin{extracode}
{\Large Character}
{\LARGE\textbf{Events}}
\tablerules
\fulltablegrid
\end{extracode}
\end{tikztimingtable}
\end{document}


# Output

With a little trickery from here (Arguments for TikZ style) you can also set draw and fill color independently and specify defaults for them. In this example the defaults are draw=black,fill=none.

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz,tikz-timing}
\colorlet{b}{blue}
\colorlet{o}{orange}
\colorlet{g}{green}
\tikzset{
set efill/.code={\pgfqkeys{/tikz/efill}{#1}},
set efill={draw/.initial=black, fill/.initial=none},
efill/.style={
set efill={#1},
\pgfkeysvalueof{/tikz/efill/draw},timing/D/background/.style={fill=\pgfkeysvalueof{/tikz/efill/fill}}
}
}
\begin{document}
\Huge
\begin{tikztimingtable}
{\LARGE Benjy}  & [efill={fill=b}]DDDD;[efill={draw=o,fill=g}]DDDD  \\
\begin{extracode}