My question is about how to improve an already working macro via the keycommand package. The small inclusion shows my efforts so far:
\documentclass{article}
\usepackage[margin=0.95in]{geometry}
\usepackage[draft,columns=1]{typogrid}
\usepackage{varwidth}
\usepackage{xkeyval}
\usepackage{keycommand}
% patch by Joseph Wright ("bug in the definition of \ifcommandkey (2010/04/27 v3.1415)"),
% https://tex.stackexchange.com/a/35794/
\begingroup
\makeatletter
\catcode`\/=8 %
\@firstofone
{
\endgroup
\renewcommand{\ifcommandkey}[1]{%
\csname @\expandafter \expandafter \expandafter
\expandafter \expandafter \expandafter \expandafter
\kcmd@nbk \commandkey {#1}//{first}{second}//oftwo\endcsname
}
}
%=======================%
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\definecolor{tikzgray}{HTML}{E5E5FF}
\definecolor{tikzyellow}{HTML}{F4F4CC}
\makeatletter
\newkeycommand\TikzBoxx[
bool draft=false,
rule=.5in,
width=.811\textwidth,
text={no text here},
scolor=tikzyellow,
lcolor=tikzgray]
[1]{%
\ifcommandkey{\commandkey{draft}}
{\begin{tikzpicture}[node distance = 0mm and 2mm,box/.style={rectangle,draw}]}
{\begin{tikzpicture}[node distance = 0mm and 2mm,box/.style={rectangle}]}
\rule{\commandkey{rule}}{0pt}%
\node (n1) [box, fill=\commandkey{scolor}] {\commandkey{text}};%
\node (n2) [box, fill=\commandkey{lcolor}, text width=\commandkey{width}, below right=of n1.north east] {%
\vbox{\noindent\ #1}
};%
\end{tikzpicture}
}
\makeatother
\def \HELLO {Hello World!}
\def \LTEXT {
Each key (may) store some \emph{tokens} and there exist\newline%
commands, described below, for setting, getting, and\newline%
changing the tokens stored in a key. However, you will\newline%
only very seldom use these commands directly.%
}
\begin{document}
\vspace{\baselineskip}
\TikzBox[text=\HELLO]{\LTEXT}
\end{document}
It works, but to my mind, it is also ugly. The problem is in the brute force way I make what should be a simple text substitution using:
\ifcommandkey{\commandkey{draft}}
{\begin{tikzpicture}[node distance = 0mm and 2mm,box/.style={rectangle,draw}]}
{\begin{tikzpicture}[node distance = 0mm and 2mm,box/.style={rectangle}]}
I initially tried building two \def
's, but that attempt erred out in the latexmake run. The idea I tried was to replace the hardcoded value in the .style={...}
with .style={\Style}
which produces the following:
! Package pgfkeys Error: I do not know the key '/tikz/rectangle,draw' and I am
going to ignore it. Perhaps you misspelled it.
After a variety of work-around attempts, I changed my approach to the code as shown.
Even though the working code only duplicates one line, I'd prefer a solution with some form of text substitution. At this point, I lack the experience needed to have a clue! All clues gratefully accepted.
\LTEXT
, after\end{tikzpicture}
, after\vbox{\noindent\ #1}
, etc. – Skillmon Dec 3 '20 at 10:35%
while you write the code and your mind is at that position anyways, than to later search for all the possible stray spaces. At least from my experience... – Skillmon Dec 4 '20 at 7:54