% !TEX TS-program = lualatex
% encoding : utf8 
% Documentation of tkzexample.sty
% Copyright 2022-2026  Alain Matthes
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
% This work has the LPPL maintenance status “maintained”.
% The Current Maintainer of this work is Alain Matthes.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                               %
%   doc   tkzexample.sty    encodage : utf8                      %
%                                                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                               %
%           Créé par Alain Matthes le 21/03/2009                %
%  Copyright (c) 2009, 2026 __AlterMundus__ All rights reserved.%
%        version : 1.51                                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\PassOptionsToPackage{unicode}{hyperref}
% DIV=14 is wanted (wide lines for the examples side by side)
\RequirePackage{silence}
\WarningFilter{typearea}{Bad type area settings}

\documentclass[DIV         = 14,
               fontsize    = 10,
               index       = totoc,
               twoside,
               cadre,
               headings    = small,
               ]{tkz-doc}
%\usepackage{etoc}
\gdef\tkznameofpack{tkzexample.sty}
\gdef\tkzversionofpack{1.51}
\gdef\tkzdateofpack{\today}
\gdef\tkznameofdoc{doc-tkzexample}
\gdef\tkzversionofdoc{1.51} 
\gdef\tkzdateofdoc{\today}
\gdef\tkzauthorofpack{Alain Matthes}
\gdef\tkzadressofauthor{}
\gdef\tkznamecollection{AlterMundus}
\gdef\tkzurlauthor{http://altermundus.fr}
\gdef\tkzengine{lualatex}
\gdef\tkzurlauthorcom{http://altermundus.fr}
\nameoffile{\tkznameofpack}
% -- Packages ---------------------------------------------------          
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{calc}
\usepackage{tkz-euclide,tkzexample,pgfornament} 
\usetikzlibrary{backgrounds}
\usepackage[colorlinks,pdfencoding=auto, psdextra]{hyperref}
\hypersetup{
      linkcolor=Gray,
      citecolor=Green,
      filecolor=Mulberry,
      urlcolor=NavyBlue,
      menucolor=Gray,
      runcolor=Mulberry,
      linkbordercolor=Gray,
      citebordercolor=Green,
      filebordercolor=Mulberry,
      urlbordercolor=NavyBlue,
      menubordercolor=Gray,
      runbordercolor=Mulberry,
      pdfsubject={Euclidean Geometry},
      pdfauthor={\tkzauthorofpack},
      pdftitle={\tkznameofpack},
      pdfcreator={\tkzengine}
}

\usepackage{fontspec}
\setmainfont{texgyrepagella}[
  Extension = .otf,
  UprightFont = *-regular ,
  ItalicFont  = *-italic  ,
  BoldFont    = *-bold    ,
  BoldItalicFont = *-bolditalic
]
\setsansfont{texgyreheros}[
  Extension = .otf,
  UprightFont = *-regular ,
  ItalicFont  = *-italic  ,
  BoldFont    = *-bold    ,
  BoldItalicFont = *-bolditalic ,
]

\setmonofont{lmmono10-regular.otf}[
  Numbers={Lining,SlashedZero},
  ItalicFont=lmmonoslant10-regular.otf,
  BoldFont=lmmonolt10-bold.otf,
  BoldItalicFont=lmmonolt10-boldoblique.otf,
]
\newfontfamily\ttcondensed{lmmonoltcond10-regular.otf}
%% (La)TeX font-related declarations:
\linespread{1.05}      % Pagella needs more space between lines
%\usepackage{unicode-math}
\usepackage[math-style=literal,bold-style=literal]{unicode-math}
\usepackage{fourier-otf}
\let\rmfamily\ttfamily
\usepackage{multicol,lscape}
\usepackage[english]{babel}
\usepackage[normalem]{ulem}
\usepackage{multirow,multido,booktabs,cellspace}
\usepackage{shortvrb,fancyvrb,bookmark,array} 

\usetikzlibrary{snakes}

%<--------------------------------------------------------------------------
% settings styles
\tkzSetUpColors[background=white,text=black]  
\AtBeginDocument{\MakeShortVerb{\|}} % link to shortvrb
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>

\begin{document}
\parindent=0pt
\tkzTitleFrame{tkzexample\\Presentation tool}
\clearpage


  \nameoffile{\tkznameofpack} 
\defoffile{\tkzname{\tkznameofpack} is a package to present examples and their sources. It is essential if you want to compile the documentation of my packages like \tkzname{tkz-euclide}. I needed for my first packages to work in UTF8 and to present my sources in French. These sources had accents so I had to adapt the code used by \tkzimp{T.Tantau} to present the examples of \tkzname{pgfmanual}. There are still some imperfections so I invite you to improve this code if necessary}.

\presentation

\vfill

Please report typos or any other comments to this documentation to: \href{mailto:al.ma@mac.com}{\textcolor{blue}{Alain Matthes}}.

This file can be redistributed and/or modified under the terms of the \LaTeX{} 
Project Public License Distributed from \href{http://www.ctan.org/}{CTAN}\  archives.


 \clearpage
 \tableofcontents
  \clearpage

\section{How to use tkzexample}

\subsection{Loading the package}

\begin{Verbatim}
\usepackage{tkzexample}          % or
\usepackage[saved]{tkzexample}   % the code of each example is saved in a file
\end{Verbatim}

\tkzname{tkzexample} loads \tkzname{calc}, \tkzname{xcolor}, \tkzname{pgfkeys}, \tkzname{mdframed} and \tkzname{fancyvrb}. To execute some \tkzname{TikZ} code, you have to load \tkzname{tikz} (or \tkzname{tkz-euclide}, etc.) yourself. The package works with |pdflatex|, |xelatex| and |lualatex|, and the code may contain accented letters (UTF-8).

\subsection{The two environments}

\begin{Verbatim}
\begin{tkzexample}[options]       \begin{tkzltxexample}[options]
  code                              code
\end{tkzexample}                  \end{tkzltxexample}
\end{Verbatim}

\begin{itemize}
\item \tkzname{tkzexample}: the code is \emph{executed} and \emph{displayed}: the result and the source are placed side by side or one above the other.
\item \tkzname{tkzltxexample}: the code is only \emph{displayed}, in a frame (as with the option \tkzname{code only} of \tkzname{tkzexample}).
\end{itemize}

The square brackets are optional. The text between |\begin{...}| and |\end{...}| is read verbatim: all the characters (|\ { } $ & # ^ _ ~ %|) are displayed as they are written. The comments (|%| until the end of the line) are displayed in slanted font and are not executed.

\subsection{How the result and the code are placed}

\begin{enumerate}
\item The code is executed in a box. If the width of the result is less than the value of the option \tkzname{width} (default |6cm|), the result and the code are placed \emph{side by side}: the result on the left, the code on the right (the option \tkzname{overhang} swaps them). The width of the code is |\linewidth-1.5em-hsep-width|.
\item If the result is wider than \tkzname{width}, the result is placed first and the code under it, on the whole width of the line.
\item With the option \tkzname{code only}, the code is not executed; it is displayed in a frame (\tkzname{mdframed}) that can be split across pages.
\item If the code is too long for the page, the option \tkzname{break code} (section \ref{sec:break}) places the result first and the code under it, in a frame that can be split across pages.
\end{enumerate}

\subsection{Options of the environment \tkzname{tkzexample}}

\textbf{Layout}

\vspace{4pt}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{4.3cm}>{\raggedright\arraybackslash}p{3cm}>{\raggedright\arraybackslash}p{\dimexpr\linewidth-7.3cm-4\tabcolsep\relax}@{}}
\toprule
option & default & meaning \\
\midrule
|width=|\meta{dim}    & |6cm|  & maximal width of the result for the side-by-side layout\\
|latex=|\meta{dim}    &        & the code is executed in a minipage of width \meta{dim} (for text); sets also \tkzname{width}\\
|vbox|                &        & the code is executed in a |\vbox| of the width of the line (for text, paragraphs)\\
|overhang|            & |false|& the code first, then the result (boolean: |overhang=false|)\\
|hsep=|\meta{dim}     & |0pt|  & horizontal space between the result and the code; with |0pt| the space is |\hfill|\\
|code only|           &        & the code is not executed, only displayed in a frame\\
|execute code|        & |true| & boolean; |execute code=false| is like |code only|\\
|break code=|\meta{v}  & |auto| & |auto|, |fill|, |always| or |never| (section \ref{sec:break}); |break code| alone means |fill|\\
|above skip=|\meta{code} & |\par| & code inserted before the example, e.g. |above skip=\par\medskip|\\
|below skip=|\meta{code} & |\par| & code inserted after the example\\
\bottomrule
\end{tabular}

\vspace{12pt}
\textbf{Colors and frames}

\vspace{4pt}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{4.3cm}>{\raggedright\arraybackslash}p{3cm}>{\raggedright\arraybackslash}p{\dimexpr\linewidth-7.3cm-4\tabcolsep\relax}@{}}
\toprule
option & default & meaning \\
\midrule
|code=|\meta{color}       & |white| & background of the code\\
|graphic=|\meta{color}    & |white| & background of the result\\
|frame code=|\meta{color} &         & frame around the code (|\fcolorbox|)\\
|frame tex=|\meta{color}  &         & frame around the result (|\fcolorbox|)\\
\bottomrule
\end{tabular}

\vspace{12pt}
\textbf{Text of the code}

\vspace{4pt}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{4.3cm}>{\raggedright\arraybackslash}p{3cm}>{\raggedright\arraybackslash}p{\dimexpr\linewidth-7.3cm-4\tabcolsep\relax}@{}}
\toprule
option & default & meaning \\
\midrule
|code style=|\meta{fonts} & |\small\ttfamily| & font of the code\\
|normal|, |small|, |very small| &           & size of the code (|\normalsize|, |\small|, |\footnotesize|)\\
|num|                     &          & numbers the lines (from 1)\\
|global num|              &          & numbers the lines, the numbering continues from the previous example\\
|numcolor=|\meta{color}   & |gray|   & color of the numbers\\
|numbkgcolor=|\meta{color}& |white|  & background of the numbers\\
|pre=|\meta{code}, |post=|\meta{code} & & code executed before / after the code of the example (not displayed)\\
\bottomrule
\end{tabular}

\vspace{12pt}
\textbf{Frame of the code with \tkzname{code only}} (options of \tkzname{mdframed})

\vspace{4pt}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{4.3cm}>{\raggedright\arraybackslash}p{3cm}>{\raggedright\arraybackslash}p{\dimexpr\linewidth-7.3cm-4\tabcolsep\relax}@{}}
\toprule
option & default & meaning \\
\midrule
|left margin|, |right margin| & |0pt| & outer margins of the frame\\
|inner left margin|   & |0pt|  & \\
|inner right margin|  & |10pt| & \\
|inner top margin|    & |6pt|  & \\
|inner bottom margin| & |.4\baselineskip| & \\
|line frame width|    & |0pt|  & width of the line of the frame\\
\bottomrule
\end{tabular}

\subsection{Options of the environment \tkzname{tkzltxexample}}

The following options of \tkzname{tkzexample} are available: |code| (background of the frame), |num|, |global num|, |numcolor|, |numbkgcolor|, |code style|, |normal|, |small|, |very small| and the options of the frame (|left margin|, \dots, |line frame width|). The option |leave comments| displays the comments as they are written (not in slanted font).

\subsection{Colors}

The colors can also be defined for the whole document with |\colorlet|:

\vspace{4pt}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{4.3cm}>{\raggedright\arraybackslash}p{3cm}>{\raggedright\arraybackslash}p{\dimexpr\linewidth-7.3cm-4\tabcolsep\relax}@{}}
\toprule
color & default & used for \\
\midrule
|graphicbackground|  & white & background of the result (option |graphic|)\\
|codebackground|     & white & background of the code (option |code|)\\
|codeonlybackground| & white & background of the frame of |code only| and |tkzltxexample|\\
|numbackground|      & white & background of the line numbers\\
|numcolor|           & gray  & line numbers\\
|textcodecolor|      & black & text of the code\\
\bottomrule
\end{tabular}

\subsection{Settings for the whole document}

The style |every tkzexample| is used by each example; its default value is |width=6cm|. To add some options to all the examples:

\begin{Verbatim}
\pgfkeys{/tkzexample/every tkzexample/.append style={code=gray!10,break code}}
\end{Verbatim}

With |.style| instead of |.append style|, the default value |width=6cm| is replaced. For \tkzname{tkzltxexample}, the style is |/tkzltxexample/every tkzltxexample|.

\subsection{Saving the code in files}

With the package option |saved|, the code of each example is written in a file and then read (section \ref{sec:saved}). The name of the file is:
\begin{Verbatim}
tkzFile-<section>-<subsection>-<subsubsection>.tex
\end{Verbatim}
 The command |\tkzSavedCode[prefix=|\meta{name}|]| changes the environment \tkzname{tkzexample}: the code is only written in a file, without any display.

\newpage
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––> 

\colorlet{graphicbackground}{blue!10!white}%
\colorlet{codebackground}{blue!20!lightgray!20}%
\colorlet{numbackground}{blue!50!black!50}%
\colorlet{numcolor}{white}%

\section{First example : no options}
\tkzname{\tkznameofpack} is based on the code of \tkzname{codeexample} of \tkzimp{T.Tantau} . I wanted to be able to use the accents of the French language in the sources. 

How to use this environment? Without any options, the interpretation of a code and the source of this code are placed one above the other.

To do this, simply place the source code in a \tkzname{tkzexample}. The colors of the different boxes show their sizes.

The colors are obtained as follows:

\begin{Verbatim}
\colorlet{graphicbackground}{blue!10!white}
\colorlet{codebackground}{blue!20!lightgray!20}
\end{Verbatim}

\begin{tkzexample}[]
\begin{minipage}{8cm}
\subsubsection{Minipage and accents  without options}
This is a test for "minipage" and   accents èçéà\&§. Since version 1.50 the brackets are optional.
\end{minipage}
\end{tkzexample}

\vspace{12pt}

\begin{Verbatim}
\begin{tkzexample}[]
\begin{minipage}{8cm}
\subsubsection{Minipage and accents  without options}
This is a test for "minipage" and   accents èçéà\&§. Since version 1.50 the brackets are optional.
\end{minipage}
\end{tkzexample}
\end{Verbatim}

\vspace{12pt}
Since version 1.50, the square brackets are optional. These two forms are valid:
\begin{Verbatim}
\begin{tkzexample}
\begin{tkzexample}[]
\end{Verbatim}

\section{Inversion of the boxes: option \tkzname{overhang}}

\tkzname{overhang} allows to swap the source and the result. \tkzname{overhang} is a boolean: |overhang=false| gives the default placement (useful if |overhang| is set globally). 

\begin{Verbatim}
\begin{tkzexample}[overhang]
\begin{tikzpicture}
  ...
\end{tkzexample}
\end{Verbatim}


\begin{tkzexample}[overhang]
\begin{tikzpicture}
  \tkzDefPoint(0,0){O}
  \tkzDefPoint(1,0){a0}
   \tkzDrawSegment(O,a0)
  \foreach \i [count=\j] in {0,...,16}{%
    \tkzDefPointWith[orthogonal normed](a\i,O)
    \tkzGetPoint{a\j}
       \pgfmathsetmacro{\c}{5*\i} 
    \tkzDrawPolySeg[fill=teal!\c](a\i,a\j,O)}
 \end{tikzpicture}
\end{tkzexample}

\newpage
\section{Boxes with the same width: option \tkzname{vbox}}

In order to present the code under the interpretation, I set the vbox option so that the interpretation and the source are in a box of the same maximum width.

\vspace{12pt}
\begin{Verbatim}
\begin{tkzexample}[vbox]
    ...
\end{tkzexample}
\end{Verbatim}
\vspace{12pt}
which gives

\begin{tkzexample}[vbox]
\begin{tikzpicture}[scale=1]
  \tikzset{new/.style={color=orange,line width=.2pt}} 
  \tkzDefPoint(0,0){A}\tkzDefPoint(6,0){D}
  \tkzDefPoint(8,0){B}\tkzDefPoint(4,0){I}
  \tkzDefLine[orthogonal=through D](A,D)
  \tkzInterLC[R](D,tkzPointResult)(I,4) \tkzGetSecondPoint{C}
  \tkzDefLine[orthogonal=through C](I,C)    \tkzGetPoint{c}
  \tkzDefLine[orthogonal=through B](A,B)    \tkzGetPoint{b}
  \tkzInterLL(C,c)(B,b) \tkzGetPoint{T}
  \tkzInterLL(A,T)(C,D) \tkzGetPoint{P}
  \tkzDrawArc(I,B)(A)
  \tkzDrawSegments(A,B A,T C,D I,C) \tkzDrawSegment[new](I,C)
  \tkzDrawLine[add = 1 and 0](C,T)   \tkzDrawLine[add = 0 and 1](B,T)
  \tkzMarkRightAngle(I,C,T)
  \tkzDrawPoints(A,B,I,D,C,T)
  \tkzLabelPoints(A,B,I,D)  \tkzLabelPoints[above right](C,T)
  \tkzMarkSegment[pos=.25,mark=s|](C,D) \tkzMarkSegment[pos=.75,mark=s|](C,D)
\end{tikzpicture}
\end{tkzexample}

\newpage

\section{Side by side: option \tkzname{latex}}

You must indicate the width of the box assigned to the interpretation, this is done with the option \tkzname{latex}:

\subsubsection{\tkzname{latex=7cm}}
\begin{tkzexample}[latex=7cm]
\begin{tikzpicture}[scale=.5]
\tkzInit[xmin=-6,ymin=-4,xmax=6,ymax=6] 
\tkzClip
\tkzSetUpLine[thin,color=teal]
\tkzDefPoint(0,0){O} 
\tkzDefPoint(132:5){A}
\tkzDefPoint(4,0){B}
\foreach \ang in {5,10,...,360}{%
 \tkzDefPoint(\ang:4){M}
 \tkzDefLine[mediator](A,M) 
 \tkzGetPoints{x}{y}
 \tkzDrawLine[add= 3 and 3](x,y)}
\end{tikzpicture}
\end{tkzexample}

\begin{Verbatim}
\begin{tkzexample}[latex=7cm]
...
\end{tkzexample}
\end{Verbatim}
\subsubsection{\tkzname{latex=8cm}}
\begin{tkzexample}[latex=8cm]
\begin{tikzpicture}[scale=.5]
\tkzInit[xmin=-6,ymin=-4,xmax=6,ymax=6]
\tkzClip
\tkzSetUpLine[thin,color=magenta]
\tkzDefPoint(0,0){O} 
\tkzDefPoint(132:4){A}
\tkzDefPoint(5,0){B}
\foreach \ang in {5,10,...,360}{%
 \tkzDefPoint(\ang:5){M}
 \tkzDefLine[mediator](A,M)
 \tkzGetPoints{x}{y}
 \tkzDrawLine[add= 3 and 3](x,y)}
\end{tikzpicture}
\end{tkzexample}

\begin{Verbatim}
\begin{tkzexample}[latex=8cm]
...
\end{tkzexample}
\end{Verbatim}
\newpage
\section{Side by side: option \tkzname{width}}
If the option \tkzname{latex= x cm} allows to reserve a box of width x cm for the code, the option \tkzname{width= x cm} allows to reserve a box of width x cm for the result.

We leave a box of 8cm for the result or drawing and the rest of the line will contain a minipage of 8cm. As you can see a new section has been created and the code is contained in a 8cm box


\begin{tkzexample}[overhang,width=6cm,code=red!10]
\begin{tikzpicture}[scale=.4]
\tkzDefPoints{0/0/P,5/0/Q,3/2/I}
\tkzDefCircle[orthogonal from=P](Q,I) 
\tkzGetFirstPoint{E}
\tkzDrawCircles(P,E Q,E)
\tkzInterCC[common=E](P,E)(Q,E) \tkzGetFirstPoint{F}
\tkzDefPointOnCircle[through =  center P angle 80 point E]
 \tkzGetPoint{A}
\tkzInterLC[common=E](A,E)(Q,E)  \tkzGetFirstPoint{C}
\tkzInterLL(A,F)(C,Q)  \tkzGetPoint{D}
\tkzDrawLines[add=0 and .75](P,Q)
\tkzDrawLines[add=0 and 2](A,E)
\tkzDrawSegments(P,E E,F F,C A,F C,D)
\tkzDrawPoints(P,Q,E,F,A,C,D)
\tkzLabelPoints(P,Q,F,C,D)
\tkzLabelPoints[above](E,A)
\end{tikzpicture}
\end{tkzexample}  

\vspace{24pt}
The options used to get this result are :
\vspace{12pt}

\begin{Verbatim}
\begin{tkzexample}[overhang,width=6cm,code=red!10]
...
\end{tkzexample}
\end{Verbatim}


\newpage
\section{Option \tkzname{code} and option \tkzname{graphic}}

This option is used to color the background of the code.

\vspace{24pt}

\begin{Verbatim}
\begin{tkzexample}[overhang,width=9cm,code=gray!20,graphic=red!15]
...
\end{tkzexample}
\end{Verbatim}

\begin{tkzexample}[overhang,width=9cm,code=gray!20,graphic=red!15]
\begin{tikzpicture}[scale=1]
 \tkzDefPoint(2,3){A}
 \tkzDefShiftPoint[A](30:3){B}
 \tkzDefShiftPoint[A](-30:3){C}
 \tkzDrawPolygon(A,B,C)
 \tkzDrawPoints(A,B,C)
 \tkzLabelPoints[right](B,C)
 \tkzLabelPoints[above left](A)
 \tkzMarkSegments[mark=|](A,B A,C B,C)
\end{tikzpicture}
\end{tkzexample}


\newpage
\section{Option \tkzname{num}}

You can number the lines of code. \tkzname{numcolor} and \tkzname{numbkgcolor} are used to define the style of the numbering. 

\subsection{Example 1}
\begin{tkzexample}[width=6cm,num,numcolor=red,numbkgcolor=white,code style=\ttfamily]
\begin{tikzpicture}[scale=0.3]
  \tkzDefPoint(-4,0){I}
  \tkzDefPoint(4,0){J}
  \tkzDefPoint(0,0){O} 
  \tkzInterCC(J,O)(O,J) \tkzGetPoints{L}{H}
  \tkzInterCC(I,O)(O,I) \tkzGetPoints{K}{G} 
  \tkzInterLL(I,K)(J,H) \tkzGetPoint{M}
  \tkzInterLL(I,G)(J,L) \tkzGetPoint{N}
  \tkzDefPointsBy[symmetry=center J](L,H){D,E} 
  \tkzDefPointsBy[symmetry=center I](G,K){C,F}
  \begin{scope}[line style/.style = {very thin,teal}]
    \tkzDrawLines[add=1.5 and 1.5](I,K I,G J,H J,L) 
    \tkzDrawLines[add=.5 and .5](I,J) 
    \tkzDrawCircles(O,I I,O J,O) 
    \tkzDrawArc[delta=0,orange](N,D)(C) 
    \tkzDrawArc[delta=0,orange](M,F)(E) 
    \tkzDrawArc[delta=0,orange](J,E)(D) 
    \tkzDrawArc[delta=0,orange](I,C)(F) 
  \end{scope}   
\end{tikzpicture} 
\end{tkzexample}
this is obtained with:

\begin{Verbatim}
\begin{tkzexample}[width=6cm,num,numcolor=red,numbkgcolor=white,code style=\ttfamily]
...
\end{tkzexample}
\end{Verbatim}



\subsection{Example 2}
\begin{tkzexample}[latex=5cm,code=red!20,num,small,hsep=24pt]
  \begin{tikzpicture}[scale=.25]
  \tkzDefPoints{0/0/A,12/0/B,6/12*sind(60)/C}
  \foreach \density in {20,30,...,240}{%
    \tkzDrawPolygon[fill=teal!\density](A,B,C)
    \pgfnodealias{X}{A}
    \tkzDefPointWith[linear,K=.15](A,B) \tkzGetPoint{A}
    \tkzDefPointWith[linear,K=.15](B,C) \tkzGetPoint{B}
    \tkzDefPointWith[linear,K=.15](C,X) \tkzGetPoint{C}}
  \end{tikzpicture}
\end{tkzexample}

\vspace{12pt}
\begin{Verbatim}
\begin{tkzexample}[latex=5cm,code=red!20,num,small]
...
\end{tkzexample}
\end{Verbatim}

\newpage
\vspace{12pt}
 The global num option allows to have a global numbering of the lines with the next code:
 
\vspace{12pt}
\begin{Verbatim}
\begin{tkzexample}[latex=7cm,global num,small,hsep=24pt]
...
\end{tkzexample}
\end{Verbatim}
\begin{tkzexample}[latex=7cm,global num,small,hsep=24pt]
\begin{tikzpicture}
  \tkzSetUpCompass[color=purple,line width=1pt]
  \tkzDefPoints{0/1/A,5/2/B,3/4/C}
  \tkzDefEquiPoints[from=C,dist=1,show,
      /tkzcompass/delta=20](A,B)
   \tkzGetPoints{E}{H}
   \tkzDrawLines[color=blue](C,E C,H A,B)
   \tkzDrawPoints[color=blue](A,B,C)
   \tkzDrawPoints[color=red](E,H)
   \tkzLabelPoints(E,H)
   \tkzLabelPoints[color=blue](A,B,C)
\end{tikzpicture}
\end{tkzexample}





%  \pgfqkeys{/tkzexample}{%
%  every tkzexample/.style={width=8cm+7pt}
%  }
%
% | \pgfqkeys{/tkzexample}{%|
% | every tkzexample/.style={width=8cm+7pt}|
% | }|

\newpage
\section{Size option for code fonts}
 The different size options for fonts are :

 \begin{enumerate}

\item very small  

\begin{tkzexample}[width=8cm,very small]
\begin{tikzpicture}[scale=.75]
  \tkzDefPoints{0/0/A,6/0/B}
  \tkzDefMidPoint(A,B)
    \tkzGetPoint{I}
  \tkzDefPointWith[orthogonal,K=-.75](B,A)
  \tkzGetPoint{C}
  \tkzInterLC(B,C)(B,I)
     \tkzGetPoints{F}{D}
  \tkzDuplicateSegment(B,F)(A,F)
  \tkzGetPoint{E}
  \tkzDrawArc[delta=10](F,E)(B)
  \tkzInterLC(A,B)(A,E)
    \tkzGetPoints{N}{M}
  \tkzDrawArc[delta=10](A,M)(E)
  \tkzDrawLines(A,B B,C A,F)
  \tkzCompass(B,F)
  \tkzDrawPoints(A,B,C,F,M,E)
  \tkzLabelPoints(A,B,C,F,M)
  \tkzLabelPoints[above](E)
\end{tikzpicture}
\end{tkzexample}

\item  small

\begin{tkzexample}[width=6cm,small]
\begin{tikzpicture}[scale=1.2]
  \tkzDefPoints{1/3/A,4/2/B}
  \tkzDefPointWith[linear,K=0.5](A,B)
  \tkzGetPoint{C}
  \tkzDrawPoints[color=red](A,B,C)
  \tkzDrawSegment(A,B)
  \tkzLabelPoints[above right=3pt](A,B,C)
\end{tikzpicture}
\end{tkzexample}


\item normal  
   
\begin{tkzexample}[width=6cm,normal]
\begin{tikzpicture}[scale=.75]
  \tikzset{new/.style={color=orange,
  line width=.2pt}} 
  \tkzDefPoints{0/0/O_1,0/1/O_2,0/3/A}
  \tkzDefPoint(15:3){F}
  \tkzInterLC(F,O_1)(O_1,A) 
  \tkzGetSecondPoint{E}
  \tkzDefLine[parallel=through O_2](E,F) 
  \tkzGetPoint{x}   
  \tkzInterLC(x,O_2)(O_2,A) \tkzGetPoints{D}{C} 
  \tkzDrawCircles(O_1,A O_2,A)
  \tkzDrawSegments[new](O_1,A E,F C,D)
  \tkzDrawSegments[purple](A,E A,F)
  \tkzDrawPoints(A,O_1,O_2,E,F,C,D)
  \tkzLabelPoints(A,O_1,O_2,E,F,C,D)
\end{tikzpicture}
\end{tkzexample}\end{enumerate}



\newpage
\section{Option \tkzname{code only}}

                                                                   
\begin{Verbatim}
\begin{tkzexample}[small,code only]
  \begin{minipage}{9cm}
  \thispagestyle{empty}
  \noindent
  \begin{tikzpicture}
     \draw (0,0)  node[circle,
                       shade,
                       ball color=Peach,minimum size=2cm]{};
     \draw[snake      = expanding waves,
           color      = Peach,
           line width = 3pt](1.2,0)--(4,0);
    \end{tikzpicture}
  \end{minipage}
\end{tkzexample}
\end{Verbatim}

The result

\begin{tkzexample}[small,code only]                            
  \begin{minipage}{9cm}                                       
  \begin{tikzpicture}                                          
     \draw (0,0)  node[circle,                                 
                       shade,                                   
                       ball color=Peach,minimum size=2cm]{};  
     \draw[snake      = expanding waves,                      
           color      = Peach,                               
           line width = 3pt](1.2,0)--(4,0);                    
    \end{tikzpicture}
\end{minipage}                                               
\end{tkzexample}                                                  



\newpage
\section{Long code: option \tkzname{break code}}\label{sec:break}

Up to version 1.45c, the code placed beside (or under) the result was set in an unbreakable box: a code longer than the remaining space on the page went to the next page, and a code longer than a page overflowed at the bottom of the page and was lost.

Since version 1.51, the option \tkzname{break code} allows the code to be split across pages. When the code must be split, the result is placed first, then the code under the result, in a frame that can be broken (with \tkzname{overhang}, the code first then the result). The line numbers (option \tkzname{num}), the background color (option \tkzname{code}) and the frame (option \tkzname{frame code}) continue on the following pages.

\vspace{12pt}
\begin{tabular}{ll}
\toprule
|break code=auto|   & default: the code is split only if the example is \\
                    & higher than a page (|\textheight|); \\
|break code=fill|   & the code is split if the example does not fit in the \\
                    & space left on the current page;\\
|break code|        & same as |break code=fill|;\\
|break code=always| & the result first, then the breakable code under it;\\
|break code=never|  & the behaviour of the version 1.45c (unbreakable box).\\
\bottomrule
\end{tabular}

\vspace{12pt}
With the default value |auto|, the layout of the examples that fit on a page does not change. To use |fill| for all the examples of a document:

\vspace{6pt}
|\pgfkeys{/tkzexample/every tkzexample/.append style={break code}}|

\vspace{12pt}
The next example is obtained with:

\vspace{6pt}
\begin{Verbatim}
\begin{tkzexample}[break code,num,code=teal!10,graphic=white]
...
\end{tkzexample}
\end{Verbatim}

\vspace{12pt}
\begin{tkzexample}[break code,num,code=teal!10,graphic=white]
\begin{tikzpicture}
  \draw[teal!20] (0,0) -- (0:2.00);
  \draw[teal!22] (0,0) -- (10:2.05);
  \draw[teal!24] (0,0) -- (20:2.10);
  \draw[teal!26] (0,0) -- (30:2.15);
  \draw[teal!28] (0,0) -- (40:2.20);
  \draw[teal!30] (0,0) -- (50:2.25);
  \draw[teal!32] (0,0) -- (60:2.30);
  \draw[teal!34] (0,0) -- (70:2.35);
  \draw[teal!36] (0,0) -- (80:2.40);
  \draw[teal!38] (0,0) -- (90:2.45);
  \draw[teal!40] (0,0) -- (100:2.50);
  \draw[teal!42] (0,0) -- (110:2.55);
  \draw[teal!44] (0,0) -- (120:2.60);
  \draw[teal!46] (0,0) -- (130:2.65);
  \draw[teal!48] (0,0) -- (140:2.70);
  \draw[teal!50] (0,0) -- (150:2.75);
  \draw[teal!52] (0,0) -- (160:2.80);
  \draw[teal!54] (0,0) -- (170:2.85);
  \draw[teal!56] (0,0) -- (180:2.90);
  \draw[teal!58] (0,0) -- (190:2.95);
  \draw[teal!60] (0,0) -- (200:3.00);
  \draw[teal!62] (0,0) -- (210:3.05);
  \draw[teal!64] (0,0) -- (220:3.10);
  \draw[teal!66] (0,0) -- (230:3.15);
  \draw[teal!68] (0,0) -- (240:3.20);
  \draw[teal!70] (0,0) -- (250:3.25);
  \draw[teal!72] (0,0) -- (260:3.30);
  \draw[teal!74] (0,0) -- (270:3.35);
  \draw[teal!76] (0,0) -- (280:3.40);
  \draw[teal!78] (0,0) -- (290:3.45);
  \draw[teal!80] (0,0) -- (300:3.50);
  \draw[teal!82] (0,0) -- (310:3.55);
  \draw[teal!84] (0,0) -- (320:3.60);
  \draw[teal!86] (0,0) -- (330:3.65);
  \draw[teal!88] (0,0) -- (340:3.70);
  \draw[teal!90] (0,0) -- (350:3.75);
  \fill[teal] (0,0) circle (2pt);
\end{tikzpicture}
\end{tkzexample}

\newpage
\section{Options of the frame of \tkzname{code only} and \tkzname{tkzltxexample}}

With the options \tkzname{code only} or with the environment \tkzname{tkzltxexample}, the code is placed in a frame (\tkzname{mdframed}). The options of the frame are:
\tkzname{left margin}, \tkzname{right margin}, \tkzname{inner left margin}, \tkzname{inner right margin}, \tkzname{inner top margin}, \tkzname{inner bottom margin} and \tkzname{line frame width}. Since version 1.50, \tkzname{inner right margin} (default 10pt) and \tkzname{inner bottom margin} (default |.4\baselineskip|) are taken into account.

\vspace{12pt}
\begin{Verbatim}
\begin{tkzexample}[code only,line frame width=1pt,inner left margin=6pt,
                   inner bottom margin=6pt]
\end{Verbatim}

\begin{tkzexample}[code only,line frame width=1pt,inner left margin=6pt,inner bottom margin=6pt]
\tkzDefPoints{0/0/A,4/0/B}
\tkzDrawSegment(A,B)
\end{tkzexample}

\section{Option \tkzname{saved} of the package}\label{sec:saved}

With |\usepackage[saved]{tkzexample}|, the code of each example is written in a file and then read. The name of the file is |tkzFile-<section>-<subsection>-<subsubsection>.tex|. Since version 1.50, when several examples are in the same subsubsection, the files are no longer overwritten: the following files are named |tkzFile-1-2-0-2.tex|, |tkzFile-1-2-0-3.tex|, etc. The prefix |tkzFile| can be changed with |\tkzSavedCode[prefix=...]|.

\section{History}

\subsection*{Version 1.51 --- 2026/10/05}
\begin{itemize}
\item New option \tkzname{break code} (|auto|, |fill|, |always|, |never|): a long code can be split across pages.
\item The option \tkzname{above skip} works (it had no effect).
\item The options may contain |\par| (for example |above skip=\par\vspace{1cm}|).
\end{itemize}

\subsection*{Version 1.50 --- 2026/10/05}
\begin{itemize}
\item The packages \tkzname{xcolor} and \tkzname{pgfkeys} are loaded: \tkzname{tkzexample} can be used without \tkzname{tikz}.
\item The brackets |[]| are optional.
\item |overhang=false| works.
\item The options \tkzname{inner right margin} and \tkzname{inner bottom margin} are used.
\item \tkzname{tkzltxexample}: the option \tkzname{hsep} works.
\item Options \tkzname{latex} and \tkzname{vbox}: an end of line in the code is a space and an empty line starts a new paragraph (the words of two lines were glued together).
\item Option \tkzname{saved}: with \tkzname{code only} the code is printed (and not the name of the file); no more overflow of 6pt when the code is under the result; the saved files are no longer overwritten.
\item |\tkzSavedCode| works without brackets.
\end{itemize}

\end{document}

