J'ai récupéré le code source d'une macro définie dans le package tkz-tools écrit par Stéphane Pasquet afin de créer ma propre macro.

Lors de la compilation via PDFlatex je reçois le message d'erreur suivant Undefined control sequence \define.

Ouvrir dans l'éditeur Overleaf
\documentclass[12pt,a4paper]{article}
\usepackage[latin1,utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{fourier}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
    \usetikzlibrary{patterns}
\usepackage{tkz-euclide}
    \usetkzobj{all}
\usepackage{xkeyval}

\begin{document}

\newcommand{\CrayonGris}
{
\draw (-0.3,0.6) -- (0,0) -- (0.3,0.6);
\draw[fill=black] (-0.1,0.2) -- (0.1,0.2) -- (0,0) -- cycle;%Pointe du crayon
\draw[fill=gray] (0.3,0.6) arc(90:180:0.1) arc(0:180:0.1) arc(0:180:0.1) arc(0:90:0.1) -- (-0.3,6) -- (0.3,6) -- cycle;%Corps du crayon
\draw (-0.2,6) -- (-0.2,0.55) (0,6) -- (0,0.55) (0.2,6) -- (0.2,0.55);%Traits verticaux
}

\begin{tikzpicture}
    \CrayonGris
\end{tikzpicture}

%-----------> \tkzPen <-------------------
\definecolor{wood}{cmyk}{0.00,0.12,0.35,0.05}
\define@cmdkey[PAS]{tkzPen}{angle}{}     % première ligne référencée par l'erreur signalée
\define@cmdkey [PAS] {tkzPen} {color}{}
\define@cmdkey [PAS] {tkzPen} {xscale}{}
\define@cmdkey [PAS] {tkzPen} {yscale}{}
\presetkeys    [PAS] {tkzPen} {color = red, angle = 30, xscale=1, yscale=1}{}
%
\newcommand{\tkzPen}[2][]
{%
\setkeys[PAS]{tkzPen}{#1}
\begin{scope}[shift={(#2)},rotate=\cmdPAS@tkzPen@angle, xscale=\cmdPAS@tkzPen@xscale, yscale=\cmdPAS@tkzPen@yscale]
\fill[wood] (0,5) circle[x radius=5mm, y radius=2mm];
\fill[wood] (-0.5,1) to[bend right=30] (-0.25,1.2) arc (180:360:0.25cm) to[bend right=30] (0.5,1) -- (0,0) -- cycle;
\fill[fill=\cmdPAS@tkzPen@color] (116.565:2mm) -- (63.435:2mm) -- (0,0) -- cycle;
\fill[fill=\cmdPAS@tkzPen@color] (-0.5,5) -- (-0.5,1) to[bend right=30] (-0.25,1.2) arc (180:360:0.25cm) to[bend right=30] (0.5,1) -- (0.5,5) arc (0:-180:0.5cm and 0.2cm);
\fill[fill=\cmdPAS@tkzPen@color] (116.565:2mm) -- (63.435:2mm) -- (0,0) -- cycle;
\fill[\cmdPAS@tkzPen@color] (0,5) circle[x radius=1.5mm, y radius=0.5mm];
\draw (-0.5,5) -- (-0.5,1) -- (0,0) -- (0.5,1) -- (0.5,5) arc (0:-360:0.5cm and 0.2cm);
\draw (-0.25,4.82) -- (-0.25,1.2) arc(180:360:0.25cm and 0.25cm) -- (0.25,4.82);
\draw (-0.25,1.2) to[bend left=30] (-0.5,1);
\draw (0.25,1.2) to[bend right=30] (0.5,1);
\end{scope}
}

\tkzPen[angle=90,color=blue,xscale=0.5,yscale=0.75]{0,0}

\end{document}

Posée 09 Sep '19, 10:05

pdesmons's gravatar image

pdesmons
274817
Taux d'acceptation : 40%

Modifiée 10 Sep '19, 00:38

Pathe's gravatar image

Pathe ♦♦
7.5k29197245


  • @ est un symbole spécial, il doit être entouré de \makeatletter ... \makeatother

  • \tkzPen[...] doit être entouré de \begin{tikzpicture}...\end{tikzpicture}


Ouvrir dans l'éditeur Overleaf
\documentclass[12pt,a4paper]{article}
\usepackage[latin1,utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{fourier}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
    \usetikzlibrary{patterns}
\usepackage{tkz-euclide}
    \usetkzobj{all}
\usepackage{xkeyval}

\makeatletter
%-----------> \tkzPen <-------------------
\definecolor{wood}{cmyk}{0.00,0.12,0.35,0.05}
\define@cmdkey [PAS] {tkzPen} {angle}{}    
\define@cmdkey [PAS] {tkzPen} {color}{}
\define@cmdkey [PAS] {tkzPen} {xscale}{}
\define@cmdkey [PAS] {tkzPen} {yscale}{}
\presetkeys    [PAS] {tkzPen} {color = red, angle = 30, xscale=1, yscale=1}{}
%
\newcommand{\tkzPen}[2][]{%
    \setkeys[PAS]{tkzPen}{#1}
    \begin{scope}[shift={(#2)},rotate=\cmdPAS@tkzPen@angle, xscale=\cmdPAS@tkzPen@xscale, yscale=\cmdPAS@tkzPen@yscale]
        \fill[wood] (0,5) circle[x radius=5mm, y radius=2mm];
        \fill[wood] (-0.5,1) to[bend right=30] (-0.25,1.2) arc (180:360:0.25cm) to[bend right=30] (0.5,1) -- (0,0) -- cycle;
        \fill[fill=\cmdPAS@tkzPen@color] (116.565:2mm) -- (63.435:2mm) -- (0,0) -- cycle;
        \fill[fill=\cmdPAS@tkzPen@color] (-0.5,5) -- (-0.5,1) to[bend right=30] (-0.25,1.2) arc (180:360:0.25cm) to[bend right=30] (0.5,1) -- (0.5,5) arc (0:-180:0.5cm and 0.2cm);
        \fill[fill=\cmdPAS@tkzPen@color] (116.565:2mm) -- (63.435:2mm) -- (0,0) -- cycle;
        \fill[\cmdPAS@tkzPen@color] (0,5) circle[x radius=1.5mm, y radius=0.5mm];
        \draw (-0.5,5) -- (-0.5,1) -- (0,0) -- (0.5,1) -- (0.5,5) arc (0:-360:0.5cm and 0.2cm);
        \draw (-0.25,4.82) -- (-0.25,1.2) arc(180:360:0.25cm and 0.25cm) -- (0.25,4.82);
        \draw (-0.25,1.2) to[bend left=30] (-0.5,1);
        \draw (0.25,1.2) to[bend right=30] (0.5,1);
    \end{scope}
}
\makeatother

\newcommand{\CrayonGris}{%
    \draw (-0.3,0.6) -- (0,0) -- (0.3,0.6);
    \draw[fill=black] (-0.1,0.2) -- (0.1,0.2) -- (0,0) -- cycle;%Pointe du crayon
    \draw[fill=gray] (0.3,0.6) arc(90:180:0.1) arc(0:180:0.1) arc(0:180:0.1) arc(0:90:0.1) -- (-0.3,6) -- (0.3,6) -- cycle;%Corps du crayon
    \draw (-0.2,6) -- (-0.2,0.55) (0,6) -- (0,0.55) (0.2,6) -- (0.2,0.55);%Traits verticaux
}

\begin{document}

\begin{tikzpicture}
    \CrayonGris
\end{tikzpicture}

\begin{tikzpicture}
    \tkzPen[angle=90,color=blue,xscale=0.5,yscale=0.75]{0,0}
\end{tikzpicture}

\end{document}
Lien permanent

Publiée 09 Sep '19, 11:24

samcarter's gravatar image

samcarter
8.2k2817
Taux d'acceptation : 57%

Modifiée 09 Sep '19, 13:37

C'est exactement ça !!!

(12 Sep '19, 18:41) pdesmons pdesmons's gravatar image
Votre réponse
(dés)activer l'aperçu

Suivre cette question

Par courriel :

Une fois que vous serez enregistré, vous pourrez souscrire à n'importe quelle mise à jour ici

Par flux RSS :

Réponses

Réponses et commentaires

Bases de Markdown

  • *italique* ou _italique_
  • **gras** ou __gras__
  • Lien ::[texte](http://url.com/ "Titre ")
  • Image : ?![alt texte](/path/img.jpg "Titre ")
  • Liste numérotée : 1. Foo 2. Bar
  • Pour ajouter un passage à la ligne, ajoutez deux espaces à l'endroit où vous souhaitez que la ligne commence.
  • Les balises HTML de base sont également prises en charge.