1

What do you recommend in order to first define a node, with content, and later redraw its content with new options (overriding the way it was first drawn)?

Small pseudo-example:

\begin{tikzpicture}
\node (M0) at (0,0) [scale=4.0] {\text{$M_0$}};
% Now imagine more tikzcode here and imagine that we need to redraw (M0), 
% but                        
% with half its size and opacity=0.5. Also imagine there are reasons
% why we did not define (M0) by "\node (M0) at (0,0) [scale=2.0,opacity=0.5] {\text{$M_0$}};" 
% in the first place.
% So we would like to be able to now write 
\redraw[scale=2.0,opacity=0.5] (M0);
% and have tikz redraw the content of the node (M0), 
% with the new  options, and nothing of the previous content visible.
\end{tikzpicture}

This is somehow related to How to access the content of a node?, at least in the sense that this is about getting at the content of (M0) by referring to its name only.

Edit: One reason why one would like to do so can be abstractly summarized thus: one would like to create a node by verbally specifying some of its properties.

For example, one would like to have:

\createnode[color=color_value,sizeofnode=sizeofnode_value,textinnode=textinnode_value] (nameofnode) at (positionofnode);

and similar thing. Using plain \newcommand does not provide such comforts, since one has to remember the meaning of the position of an argument. That is, while working one has to be able to answer questions like "What was the meaning of the ninth argument of my new command again?

I gather from the literature that to solve this one should use

pgfkeys

to create ones own customizable node-command, having options with telling names.

Therefore:

Additional question. Do you agree that using pgfkeys is the way to go for the current problem, too?

Sebastiano
  • 54,118
  • 2
    Again, I'd use \newcommand, but I know you don't want that. Is this for a beamer presentation by the way? (Because it doesn't make sense for a normal document.) – Torbjørn T. May 18 '17 at 09:43
  • @Torbjørn T. Thanks. It is not so much that I do not want to do it using \newcommand, but doing it that way appears more complicated to me. It is not clear enough to me why that is so. I will describe why, provided I can explain it succinctly and clearly. – Peter Heinig May 18 '17 at 09:53
  • By the way, how to @ your pseudonym without using a copying functionality, i.e., how to @ it by typing only? – Peter Heinig May 18 '17 at 09:55
  • 1
    When you start typing @Torbj.. you should see a small box with my username appear. Hit the Tab-key to complete it. – Torbjørn T. May 18 '17 at 10:31
  • @PeterHeinig, if I understand correctly your question, you like to invent new syntax for shape options ... now you can write \node[shape=rectangle, minimal width=<width>, ...] at (<coordinate>) {text}. If your all nodes have something common, than you can this prescribe with every node/.style={<common properties>}, for example draw, font etc. Of course, there is other possibilities ... – Zarko Jun 06 '17 at 08:07

1 Answers1

1

Here's a more common approach: use iterations

  • start with basic code
  • refine and compile again
  • that's dynamic in itself.

The following example tries mimicking this process. Think of modifying your (M0) instead, or WITHOUT changing the coordinates, run by run:

  • start small \node (M1) at (3, 0) {1. start small};
  • add a style \node[sta] (M2) at (3,-1) {2. add a style};
  • modify style until it's nice \node[stb] (M3) at (3,-3) {3. adapt style};

So your style develops:

  • from missing
  • via {draw=orange,text=red},
  • to finally {draw=orange!80!yellow!50,text=red,minimum height=15mm,dashed,line width=3pt},

If you also are unsure about the textual content of a node, you can e.g.:

  • edit it in-place
  • define a couple of macros in the preamble

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{amsmath}

\begin{document} \begin{tikzpicture}[ sta/.style={draw=orange,text=red}, stb/.style={draw=orange!80!yellow!50,text=red,minimum height=15mm,dashed,line width=3pt}, ] % ~~~ your example ~~~~~~~~~~~~~ \node (M0) at (0,0) [scale=4.0] {\text{$M_0$}};

% ~~~ better ways to do it ~~~~~~~~~
\node       (M1) at (3, 0) {1. start small}; 
\node[sta]  (M2) at (3,-1) {2. add a style}; 
\node[stb]  (M3) at (3,-3) {3. adapt style}; 

\end{tikzpicture} \end{document}

MS-SPO
  • 11,519