EDIT: I have started WhizzyTikZ with the goal of having WhizzyEdit work with (fairly) arbitrary TikZ code. It's good enough now that I have used it on one project.
Background:
WhizzyTeX is a system for showing live updates of a dvi (or pdf). When used with the Active-dvi viewer it also has the ability (called WhizzyEdit) to move or resize elements with the mouse. The elements must have special markup indicating their position and size via source specials. In advi changes are made with the mouse and then brought back into emacs where the position is changed in the code (based on a line number and command name). When it is recompiled the element is in the new position.
For this to work you use the \adviedit
macro. You can wrap it in another macro–just tell it the name of the new macro so that WhizzyTeX knows what to change in the source. Also the macro must have a first argument something like {x=1.2,y=3.4}
so that it knows how to edit the source.
My Question:
Is there some way to add the source specials to PGF/TikZ primitives so that advi would know where all TikZ nodes are and thus be able to move them? After that there might need to be some heuristics involved with how to edit the source, but I think I can handle that part. Since I know nothing about PGF/TikZ internals I don't know if it would even be possible to write source specials for "every node".
I know there is an every node
style, but it doesn't seem to execute code. There is also the execute at begin scope
, which can probably be used to ensure that \adviedit
and TikZ use the same units, but it won't help with adding specials. In a path, execute at begin to
and execute at end to
might be useful, but for isolated nodes it seems useless.
Eventually I would like a package that would override (well, hopefully just append to) some internal TikZ macros allowing me to move any TikZ node and perhaps even play with Bezier curves etc.
Right now I have the first step, namely a macro that draws a node and inserts the \adviedit
. It uses tkz-graph
so that I don't have to parse the x=#,y=#
myself.
\documentclass[12pt]{article}
\usepackage{advi}
\usepackage{tikz}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm]
\SetVertexNoLabel
% For reference
\draw (0,0) rectangle (15,15);
% My attempt to
\def\mynode#1{%
\setedit{unit=1cm}
\adviedit{comm=\mynode,w=1,h=1,#1}{}
\Vertex[#1]{}
}
% "Turn off" WhizzyEdit
% \def\mynode#1{\Vertex[#1]{}}%
\mynode{x=8.9921,y=8.6836}
\mynode{x=7.2178,y=9.1965}
\mynode{x=6.464,y=6.6085}
\mynode{x=7.2497,y=7.8264}
\mynode{x=3.7562,y=6.9931}
\mynode{x=3.5366,y=10.3264}
\mynode{x=9.3650,y=7.0893}
\mynode{x=10.1343,y=5.4871}
\mynode{x=7.3460,y=12.1536}
\mynode{x=2.2179,y=1.5769}
\end{tikzpicture}
\end{document}
Note that labels aren't placed correctly which is why I turned them off. That's not my fault (I don't think).
Best Answer
I've done a little experimenting, and have some code that I hope will help you. It's not a complete solution by any means.
It appears that an
adviedit
able macro has to be of the form\macro{x=<value>,y=<value>}
forwhizzytex
to be able to feed the numbers back in. My first idea was simply to add a style to a\node
so it looked something like\node[advi={x=<value,y=<value>}]
but that didn't seem to work (maybe more experimenting would reveal a way to make this work). So I defined a wrapper around the\node
command which took the coordinates at the start and then handed control over to the original\node
. Because of the way that\node
executes the options it is given (as in\node[draw]
), there's no problem with this.Here's the code. I'll comment on it in the code.
I don't trust trying this with the
standalone
class, so here's a screenshot instead.The blue boxes and green lines are those drawn by
advi
. Note that they are drawn under the drawing, so are overwritten by the border of theA
node and the filled region of theB
node. They are draggable.The green lines show that the coordinates are relative to something. Experimenting shows that they are relative to the
(0,0)
inside the picture - which is what it should be. (A quick look at the code foradvi.sty
shows that there is some interaction with PGF builtin which probably takes care of this bit).(Lastly, this looks very intriguing and definitely worth learning about.)