1

How do I reset the counters for the steps and diagrams after each new proposition in my environment code?

\documentclass{book}

\usepackage{blindtext} \usepackage{tikz} \usepackage{tkz-euclide}

\newcommand{\AB}{0.75} % A and B added <<<<<<<<<<<<<< \newcommand{\C}{1.5} % C added <<<<<<<<<<<<<< \newcommand{\AD}{0.75} % D added<<<<<<<<<<<<<< \newcommand{\Asize}{0.25} % Angle added <<<<<<<<<<<<<<

\newcommand{\AG}{1.5}

% Standard packages \usepackage{ float, graphicx }

% Set page margins \usepackage[top=1.0in, bottom=1.0in, left=1.0in, right=1.0in]. {geometry}

\setlength{\marginparwidth}{0pt}

% Set nice page headers \usepackage{fancyhdr} \pagestyle{fancy}

% Paragraph style \setlength{\parindent}{0em} \setlength{\parskip}{1em}

% Proposition environment \newenvironment{proposition} {\begin{center}\em} {\end{center}}

\newcounter{CountStep} \newcounter{CountDiag}

\newenvironment{diagram} %Where i think I need to change something<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< {\stepcounter{CountStep}\stepcounter{CountDiag}\vspace{10pt} Step~\theCountStep\par \begin{center} \begin{tikzpicture}} {\end{tikzpicture}\vspace{-5pt}\par Diagram~\theCountDiag \end{center}}

\begin{document}

\chapter{Proposition 1-6} \section{Proposition 6} \begin{proposition} If two angles (B, C) of a triangle be equal, the sides (AC, AB) opposite to them are also equal. \end{proposition}

\begin{diagram}

\tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C}

\tkzDrawPolygon(A,B,C)

\end{diagram}

text\

\begin{diagram}

\tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C}

\tkzDefPointOnLine[pos=0.7](A,C)\tkzGetPoint{D}

\tkzDrawPolygon(A,B,C)

\end{diagram}

\clearpage

\section{Proposition 7}

\begin{proposition} text \end{proposition}

\begin{center} \begin{tabular}{ccc} \begin{tikzpicture} \tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C,1/\AD/D}

\tkzDefPointOnLine[pos=0.5](B,C)\tkzGetPoint{E}

\tkzDrawPolygon(A,B,C)

\end{tikzpicture} & \begin{tikzpicture} \tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C,1/\AD/D}

\tkzDefPointOnLinepos=0.5\tkzGetPoint{E}

%\tkzDrawPolygon(A,B,C)

\end{tikzpicture} & \begin{tikzpicture} \tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C,1/\AD/D}

\tkzDefPointOnLine[pos=0.5](B,C)\tkzGetPoint{E}

\tkzDrawPolygon(A,B,C) \tkzDrawPolygon(A,B,D)

\end{tikzpicture} \end{tabular} \end{center} text

\begin{diagram}

\tkzDefPoints{-\AB/0/A,\AB/0/B,0/\C/C,1/\AD/D}

\tkzDefPointOnLine[pos=0.5](B,C)\tkzGetPoint{E}

\tkzDrawPolygon(A,B,C) \tkzDrawPolygon(A,B,D)

\end{diagram} text

\clearpage

\end{document}

Thanks

Paul A
  • 1,055
  • 4
  • 14
  • 4
    Can you please boil down the code to its relevant parts? I.e. it still must compile, but most of the lines tell your content, while making your problem less visible, i.e. harder to help. Thank you – MS-SPO Nov 26 '23 at 14:08
  • 5
    as far as I can tell you just want to declare the CountStep counter to reset on proposition (use the optional argument to \newcounter) – David Carlisle Nov 26 '23 at 14:14
  • 2
    unrelated but never end a paragraph with \\ as in text\\ see https://tex.stackexchange.com/questions/334246/what-does-the-phrase-underfull-hbox-badness-10000-in-paragraph-actually-mea/334249#334249 – David Carlisle Nov 26 '23 at 15:32
  • Thanks for your comments I found; \usepackage{etoolbox} \AtBeginEnvironment{proposition}{\setcounter{CountStep}{0}}

    \usepackage{etoolbox} \AtBeginEnvironment{proposition}{\setcounter{CountDiag}{0}} worked for me

    – Paul A Nov 26 '23 at 18:21
  • 1
    since you defined the proposition environment yourself, you can just add the reset code to the environment definition (just before \begin{center}) instead of patching it using etoolbox. – Willie Wong Nov 27 '23 at 04:34

0 Answers0