Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pimp codeexamples (issue #640) #711

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b7c5702
- commented line that adds all libraries to the extracted codeexample…
Mo-Gul Jun 24, 2019
9937193
- finished adding libraries to codeexamples of the tutorial doc files
Mo-Gul Jun 25, 2019
8141bdd
- added `pre` stuff to codeexamples of the tutorial doc files so fewe…
Mo-Gul Jun 25, 2019
8ec9894
- adapted `extract.lua`
Mo-Gul Jun 26, 2019
bcae73f
- missed to update `pgfmanual-en-macros.tex`
Mo-Gul Jun 26, 2019
125f880
- finished switching from `libraries/tikz={...}` to `preamble={\useti…
Mo-Gul Jun 27, 2019
cb17274
- continued adding code to make extracted `codeexample`s work
Mo-Gul Jul 1, 2019
c39c6a5
- continued adding code to make extracted `codeexample`s work
Mo-Gul Jul 2, 2019
6ef58e6
- changed order of `setup code` and `preamble` in `extract.lua`
Mo-Gul Jul 2, 2019
5230356
- continued adding code to make extracted `codeexample`s work
Mo-Gul Jul 3, 2019
f1b8890
- % TODOsp: ... --> % TODOsp: codeexamples: ...
Mo-Gul Jul 3, 2019
da50350
- removed an unnecessary empty line
Mo-Gul Jul 3, 2019
9da30c6
- adapted `extract.lua` after Henri changed it in Master to also acco…
Mo-Gul Jul 13, 2019
09723c9
- accounted for some more `codeexample`s in `tex/generic/graphdrawing…
Mo-Gul Jul 14, 2019
2428348
Merge branch 'master' into PimpCodeexamples
Mo-Gul Jul 16, 2019
4dd4ac8
Revert "Merge branch 'master' into PimpCodeexamples"
Mo-Gul Jul 18, 2019
30ad80a
- removed commented/unnecessary stuff from `extract.lua`
Mo-Gul Jul 18, 2019
357a9af
- implemented suggestions given in https://github.com/pgf-tikz/pgf/pu…
Mo-Gul Jul 18, 2019
8c51d28
- commented some more `\begin{codeexample}[setup code,hidden]`
Mo-Gul Jul 18, 2019
900d477
- also need to Lua comment LaTeX comment in the Lua documentation files
Mo-Gul Jul 18, 2019
ed02c79
- moved `setup code` before `pre` in `extract.lua`
Mo-Gul Jul 20, 2019
26e55a3
- corrected wrongly commented Lua comments in the Lua documentation f…
Mo-Gul Jul 20, 2019
e66db1b
- continued(/finished) moving `setup code,hidden` to `preamble` of th…
Mo-Gul Jul 23, 2019
6fb64f8
- missed to commit/push the Lua documentation stuff
Mo-Gul Jul 24, 2019
87099dd
- fixed issue #718 ([manual] \usepgflibrary vs. \usetikzlibrary)
Mo-Gul Jul 27, 2019
3d5a3d8
- included issue #720 ("sub-library" should load "main library" by de…
Mo-Gul Jul 28, 2019
5528f3e
- moved `colorlet` to the `codeexample` itself instead of to `pre` in…
Mo-Gul Aug 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions doc/generic/pgf/extract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ local function walk(sourcedir, targetdir)
goto continue
end

-- Skip those that say "code only"
if not options["code only"] then
-- Skip those that say "code only" or "setup code"
if not options["code only"] and not options["setup code"] then
local newname = name .. "-" .. n .. ".tex"
local examplefile = io.open(targetdir .. newname, "w")

examplefile:write"\\documentclass{article}\n"
examplefile:write"\\documentclass{standalone}\n"
examplefile:write"\\usepackage{fp,pgf,tikz,xcolor}\n"
examplefile:write(preamble) -- TODO: this has to go
-- examplefile:write(preamble) -- TODO: this has to go
examplefile:write(setup_code)
examplefile:write(options["preamble"] and options["preamble"] .. "\n" or "")
examplefile:write"\\begin{document}\n"
examplefile:write"\\makeatletter\n" -- TODO: this has to go
examplefile:write(setup_code)
-- examplefile:write"\\makeatletter\n" -- TODO: this has to go
Mo-Gul marked this conversation as resolved.
Show resolved Hide resolved

local pre = options["pre"] or ""
pre = pre:gsub("##", "#")
examplefile:write(pre .. "\n")
Expand Down
8 changes: 4 additions & 4 deletions doc/generic/pgf/text-en/pgfmanual-en-base-actions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ \subsection{Arrow Tips on a Path}

To ``clear'' the start arrow, say |\pgfsetarrowsstart{}|.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usepgflibrary{arrows.meta}}]
\begin{pgfpicture}
\pgfsetarrowsstart{Latex[length=10pt]}
\pgfpathmoveto{\pgfpointorigin}
Expand All @@ -368,7 +368,7 @@ \subsection{Arrow Tips on a Path}
\begin{command}{\pgfsetarrowsend\marg{end arrow tip specification}}
Sets the arrow tip kind used at the end of a path.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usepgflibrary{arrows.meta}}]
\begin{pgfpicture}
\pgfsetarrowsstart{Latex[length=10pt]}
\pgfsetarrowsend{Computer Modern Rightarrow}
Expand All @@ -385,7 +385,7 @@ \subsection{Arrow Tips on a Path}
specification}|-|\meta{end arrow tip specification}. In this case, both the
start and the end arrow specification are set:
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usepgflibrary{arrows.meta}}]
\begin{pgfpicture}
\pgfsetarrows{Latex[length=10pt]->>}
\pgfpathmoveto{\pgfpointorigin}
Expand All @@ -409,7 +409,7 @@ \subsection{Arrow Tips on a Path}
This command is useful if you wish arrows or lines to ``stop shortly
before'' a given point.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usepgflibrary{arrows.meta}}]
\begin{pgfpicture}
\pgfpathcircle{\pgfpointorigin}{5mm}
\pgfusepath{stroke}
Expand Down
22 changes: 17 additions & 5 deletions doc/generic/pgf/text-en/pgfmanual-en-base-animations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ \section{Animations}
This module contains the basic layer support of animations, which is
documented in the following.
\end{pgfmodule}
%
\begin{codeexample}[setup code,hidden]
\usepgfmodule{animations}
\end{codeexample}

This section described the basic layer support of animations, the \tikzname\
support is described in Section~\ref{section-tikz-animations}. As always,
Expand Down Expand Up @@ -65,7 +69,11 @@ \subsection{Overview}
you to create ``snapshots'' of animations. As an example, the following code
shows how the same drawing is shown at different ``time snapshots'':
%
\begin{codeexample}[width=3.9cm]
\begin{codeexample}[
width=3.9cm,
preamble={\usetikzlibrary{animations}
\def\pgfname{\textsc{pgf}}
Mo-Gul marked this conversation as resolved.
Show resolved Hide resolved
}]
\tikz [make snapshot of=0.5s] \scoped :rotate = { 0s = "0", 2s = "90" }
\node [draw=blue, very thick] {\pgfname};
\tikz [make snapshot of=1s] \scoped :rotate = { 0s = "0", 2s = "90" }
Expand Down Expand Up @@ -464,7 +472,7 @@ \subsubsection{``Anti-Animations'': Snapshots}
is used in a \TeX\ scope, no animation is created and no support by the
driver is needed (so, it works with \textsc{pdf}).
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{animations}}]
\tikz [make snapshot of=1s,
animate = { myself: = {
:rotate = { 0s = "0", 2s = "90" },
Expand Down Expand Up @@ -1113,11 +1121,15 @@ \subsection{Animating Transformations and Views}

In order to use a view, you first need to create a view, which is done
using a |{pgfviewboxscope}|, see Section~\ref{section-base-view}, which is
used by the |view| library internally. You can then animate the view using
used by the |views| library internally. You can then animate the view using
the |view| attribute. The values passed to the |entry| key must be two
\pgfname-points, each surrounded by parentheses.
%
\begin{codeexample}[animation list={0.5,1,1.5,2},animation bb={(1.1,-0.9) rectangle (2.9,0.9)}]
\begin{codeexample}[
preamble={\usetikzlibrary{views}},
animation list={0.5,1,1.5,2},
animation bb={(1.1,-0.9) rectangle (2.9,0.9)},
]
\tikz [very thick] {
\pgfanimateattribute{view}{
whom = me.view, begin on = {click, of next=node}, freeze at end,
Expand All @@ -1133,7 +1145,7 @@ \subsection{Animating Transformations and Views}
}
\end{codeexample}

\begin{codeexample}[width=2cm]
\begin{codeexample}[width=2cm,preamble={\usetikzlibrary{views}}]
\tikz [very thick] {
\pgfanimateattribute{view}{
whom = me.view, begin on = {click, of next=n1}, freeze at end,
Expand Down
63 changes: 61 additions & 2 deletions doc/generic/pgf/text-en/pgfmanual-en-base-arrows.tex
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,66 @@ \subsection{Declaring an Arrow Tip Kind}
},
defaults = { length = 4cm }
}
\begin{codeexample}[]
\begin{codeexample}[
preamble={\usetikzlibrary{arrows.meta}},
pre={\pgfdeclarearrow{
name = foo,
parameters = { \the\pgfarrowlength },
setup code = {
% The different end values:
\pgfarrowssettipend{.25\pgfarrowlength}
\pgfarrowssetlineend{-.25\pgfarrowlength}
\pgfarrowssetvisualbackend{-.5\pgfarrowlength}
\pgfarrowssetbackend{-.75\pgfarrowlength}
% The hull
\pgfarrowshullpoint{.25\pgfarrowlength}{0pt}
\pgfarrowshullpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}
\pgfarrowshullpoint{-.75\pgfarrowlength}{-.5\pgfarrowlength}
% Saves: Only the length:
\pgfarrowssavethe\pgfarrowlength
},
drawing code = {
\pgfpathmoveto{\pgfqpoint{.25\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfqpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}}
\pgfpathlineto{\pgfqpoint{-.5\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfqpoint{-.75\pgfarrowlength}{-.5\pgfarrowlength}}
\pgfpathclose
\pgfusepathqfill
},
defaults = { length = 4cm }
}},
]
\tikz \draw [-foo] (0,0) -- (8,0);
\end{codeexample}
\begin{codeexample}[]
\begin{codeexample}[
preamble={\usetikzlibrary{arrows.meta,bending}},
pre={\pgfdeclarearrow{
name = foo,
parameters = { \the\pgfarrowlength },
setup code = {
% The different end values:
\pgfarrowssettipend{.25\pgfarrowlength}
\pgfarrowssetlineend{-.25\pgfarrowlength}
\pgfarrowssetvisualbackend{-.5\pgfarrowlength}
\pgfarrowssetbackend{-.75\pgfarrowlength}
% The hull
\pgfarrowshullpoint{.25\pgfarrowlength}{0pt}
\pgfarrowshullpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}
\pgfarrowshullpoint{-.75\pgfarrowlength}{-.5\pgfarrowlength}
% Saves: Only the length:
\pgfarrowssavethe\pgfarrowlength
},
drawing code = {
\pgfpathmoveto{\pgfqpoint{.25\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfqpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}}
\pgfpathlineto{\pgfqpoint{-.5\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfqpoint{-.75\pgfarrowlength}{-.5\pgfarrowlength}}
\pgfpathclose
\pgfusepathqfill
},
defaults = { length = 4cm }
}},
]
\tikz \draw [-{foo[length=2cm,bend]}] (0,0) to [bend left] (3,0);
\end{codeexample}

Expand Down Expand Up @@ -846,10 +902,13 @@ \subsubsection{Defining New Arrow Keys}
|\pgfarrowstheparameters|. Here is an example, where |\showvalueofmacro| is
used in this example to show the value stored in a macro:
%
\begin{codeexample}[setup code,hidden]
\makeatletter
\def\showvalueofmacro#1{%
\texttt{\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\pgfutil@gobble\expandafter\expandafter\expandafter\string\expandafter\csname#1\endcsname}
}
\end{codeexample}
%
\begin{codeexample}[]
\pgfarrowsthreeparameters{2pt 1}
\showvalueofmacro\pgfarrowstheparameters
Expand Down
21 changes: 12 additions & 9 deletions doc/generic/pgf/text-en/pgfmanual-en-base-decorations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ \section{Decorations}
need to load this module to use decorations. This module is automatically
loaded by the different decoration libraries.
\end{pgfmodule}
%
\begin{codeexample}[setup code,hidden]
\usetikzlibrary{decorations}
\end{codeexample}


\subsection{Overview}
Expand All @@ -24,14 +28,14 @@ \subsection{Overview}
and, while doing so, either drawing something or constructing a new path. This
could be as simple as extending a path with a ``zigzagged'' line\ldots
%
\begin{codeexample}[preamble={\usetikzlibrary{decorations,decorations.pathmorphing}}]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.pathmorphing}}]
\tikz \draw decorate[decoration=zigzag] {(0,0) -- (3,0)};
\end{codeexample}
%
\ldots but could also be as complex as typesetting text along a path:
%
{\catcode`\|12
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.text}}]
\tikz \path decorate [decoration={text along path,
text={Some text along a path}}]
{ (0,2) .. controls (2,2) and (1,0) .. (3,0) };
Expand Down Expand Up @@ -285,7 +289,7 @@ \subsection{Declaring Decorations}
parts of the rest of the output path for the following
invocation. Here is an example:
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{shapes.geometric}}]
\pgfdeclaredecoration{stars}{initial}{
\state{initial}[width=15pt]
{
Expand All @@ -306,7 +310,6 @@ \subsection{Declaring Decorations}
.. controls (0,-5) and (3,-5) .. (3,-3);
\end{codeexample}
%

\item After the \meta{code} has been executed (possibly more than
once, if the |repeat state| option is used), the state switches
to whatever state has been specified inside the \meta{options}
Expand Down Expand Up @@ -604,7 +607,7 @@ \subsection{Using Decorations}
\meta{before code} is executed. After the decoration automaton has
finished, \meta{after code} is executed.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.pathmorphing}}]
\begin{tikzpicture}[decoration={segment length=5pt}]
\draw [help lines] grid (3,2);
\begin{pgfdecoration}{{curveto}{1cm},{zigzag}{2cm},{curveto}{1cm}}
Expand All @@ -622,7 +625,7 @@ \subsection{Using Decorations}
path. Thus, it is possible to specify lengths like
|\pgfdecoratedpathlength/3|.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.pathmorphing}}]
\begin{tikzpicture}[decoration={segment length=5pt}]
\draw [help lines] grid (3,2);
\begin{pgfdecoration}{
Expand Down Expand Up @@ -653,7 +656,7 @@ \subsection{Using Decorations}
This means that if decorations do not use their own path, it is possible to
do something with them and continue from the correct place.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.pathmorphing}}]
\begin{tikzpicture}
\draw [help lines] grid (3,2);
\begin{pgfdecoration}{
Expand Down Expand Up @@ -764,7 +767,7 @@ \subsection{Using Decorations}
Note when applying multiple decorations, this will be reset between
decorations, so it needs to be specified for each segment.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.pathmorphing}}]
\begin{tikzpicture}
\draw [help lines] grid (3,2);
\begin{pgfdecoration}{
Expand Down Expand Up @@ -906,7 +909,7 @@ \subsubsection{Declaring Meta-Decorations}

Here is a complete example of a meta-decoration:
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{decorations.pathmorphing}}]
\pgfdeclaremetadecoration{arrows}{initial}{
\state{initial}[width=0pt, next state=arrow]
{
Expand Down
4 changes: 2 additions & 2 deletions doc/generic/pgf/text-en/pgfmanual-en-base-images.tex
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ \subsection{Using an Image}
The following example demonstrates the effect of using |\pgfuseimage|
inside a colormixin environment.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usepackage{xxcolor}}]
\pgfdeclareimage[interpolate=true,width=1cm,height=1cm]
{image1.!25!white}{brave-gnu-world-logo.25}
\pgfdeclareimage[interpolate=true,width=1cm]
Expand Down Expand Up @@ -194,7 +194,7 @@ \subsection{Using an Image}
You can ``save'' the image for later usage by invoking |\pgfaliasimage| on
|pgflastimage|.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usepackage{xxcolor}}]
\begin{colormixin}{25!white}
\begin{pgfpicture}
\pgftext[at=\pgfpoint{1cm}{5cm},left,base]
Expand Down
11 changes: 7 additions & 4 deletions doc/generic/pgf/text-en/pgfmanual-en-base-nodes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ \subsubsection{Creating Multi-Part Nodes}
Finally, when the node is drawn, the boxes are placed at the anchor
positions |text| and |lower|.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{shapes}}]
\setbox\pgfnodeparttextbox=\hbox{$q_1$}
\setbox\pgfnodepartlowerbox=\hbox{01}
\begin{pgfpicture}
Expand Down Expand Up @@ -552,7 +552,7 @@ \subsubsection{Referencing Anchors of Nodes in the Same Picture}
|\pgfpointanchor| without any transformations in force. Here is an example:
%
\makeatletter
\begin{codeexample}[]
\begin{codeexample}[pre={\makeatletter}]
\begin{pgfpicture}
\pgftransformrotate{30}
\pgfnode{rectangle}{center}{Hello World!}{x}{\pgfusepath{stroke}}
Expand Down Expand Up @@ -726,7 +726,7 @@ \subsection{Special Nodes}
area. Note that excessive use of this option (keeping track of dozens of
bounding boxes at the same time) will slow things down.
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{scopes}}]
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
{ [local bounding box=outer box]
Expand Down Expand Up @@ -1240,7 +1240,10 @@ \subsubsection{Command for Declaring New Shapes}
on inheritance:
%
\makeatletter
\begin{codeexample}[]
\begin{codeexample}[
preamble={\usetikzlibrary{shapes.geometric}},
pre={\makeatletter},
]
\pgfdeclareshape{document}{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
Expand Down
33 changes: 32 additions & 1 deletion doc/generic/pgf/text-en/pgfmanual-en-base-patterns.tex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ \subsection{Overview}
shading, which means that the color changes smoothly between two (or more)
different colors. Third, you can fill it using a tiling pattern and it is
explained in the following how this is done.
%
\begin{codeexample}[setup code,hidden]
\usetikzlibrary{patterns}
\end{codeexample}

A tiling pattern can be imagined as a rectangular tile (hence the name) on
which a small picture is painted. There is not a single tile, but
Expand Down Expand Up @@ -214,7 +218,34 @@ \subsection{Setting a Pattern}
the \meta{color} parameter is ignored. For form-only patterns, the
\meta{color} parameter specifies the color to be used for the pattern.
%
\begin{codeexample}[]
\begin{codeexample}[
preamble={\pgfdeclarepatternformonly{stars}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
\pgftransformshift{\pgfpoint{.5cm}{.5cm}}
\pgfpathmoveto{\pgfpointpolar{0}{4mm}}
\pgfpathlineto{\pgfpointpolar{144}{4mm}}
\pgfpathlineto{\pgfpointpolar{288}{4mm}}
\pgfpathlineto{\pgfpointpolar{72}{4mm}}
\pgfpathlineto{\pgfpointpolar{216}{4mm}}
\pgfpathclose%
\pgfusepath{fill}
}
\pgfdeclarepatterninherentlycolored{green stars}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
\pgfsetfillcolor{green!50!black}
\pgftransformshift{\pgfpoint{.5cm}{.5cm}}
\pgfpathmoveto{\pgfpointpolar{0}{4mm}}
\pgfpathlineto{\pgfpointpolar{144}{4mm}}
\pgfpathlineto{\pgfpointpolar{288}{4mm}}
\pgfpathlineto{\pgfpointpolar{72}{4mm}}
\pgfpathlineto{\pgfpointpolar{216}{4mm}}
\pgfpathclose%
\pgfusepath{stroke,fill}
}}]
Mo-Gul marked this conversation as resolved.
Show resolved Hide resolved
\begin{tikzpicture}
\pgfsetfillpattern{stars}{red}
\filldraw (0,0) rectangle (1.5,2);
Expand Down
Loading