1

form Numbering equation and theorems outside the margin

I got a solution. but I want to reset the number. like (1) (2) (3) (1) (2) (3) (4) (5) (1) (2) (3) how can i do?


\documentclass[leqno]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{amsmath, amsthm}
\usepackage{mdframed}
%% Code by David Carlisle at https://tex.stackexchange.com/a/258575/38080
\makeatletter
\def\formatout#1{\hbox{\hskip1sp\m@th\llap{%
    \normalcolor\normalfont#1\hspace{1.0cm}}}}
\let\oldmaketag@@@\maketag@@@
\def\oldtagform@#1{\oldmaketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\oldtagform@{\ref{#1}}}}
\def\maketag@@@#1{\formatout{#1}}
%
% redefine the amsthm theorem start macro to use \formatout
%
\def\@begintheorem#1#2[#3]{%
  \deferred@thm@head{\the\thm@headfont \thm@indent
    \@ifempty{#1}{\let\thmname\@gobble}{\let\thmname\@iden}%
    \@ifempty{#2}{\let\thmnumber\@gobble}{\let\thmnumber\thmnumber}%
    \@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
    \thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
    \the\thm@headpunct
    \thmheadnl % possibly a newline.
    \hskip\thm@headsep
  }%
  \ignorespaces}%
\makeatother
\swapnumbers
\def\thmnumber#1{\formatout{(#1)}}
% https://tex.stackexchange.com/a/303245/38080
\newtheorem{thm}[equation]{Theorem}
\newtheorem{exa}[equation]{Example}
\begin{document}

Let's start with
\begin{equation}
    E=mc^2
    \label{eq:mc2}
\end{equation}
so we go to:

\begin{thm}{Einsteins:}
    $E$ is equal to $m$ $c$ squared
    \label{thE}
\end{thm}

This leads to this

\begin{exa}{Example:}
    $E$ is equal to $m$ multiplied a BIG number
    \label{exE}
\end{exa}

% innerleftmargin+leftmargin must be 0pt...
\begin{mdframed}[backgroundcolor=gray!20, innerleftmargin=0pt, linewidth=0pt]
Also
\begin{equation}
    m=E/c^2
    \label{eq:mc2i}
\end{equation}
\end{mdframed}

And the references are Eq.~\ref{eq:mc2}, Th.~\ref{thE}, Ex.~\ref{exE}.

\end{document}
5
  • 5
    \setcounter{equation}{0} ? Sep 12, 2019 at 13:13
  • Maybe this can help ctan.org/pkg/chngcntr ?
    – Sango
    Sep 12, 2019 at 13:16
  • 2
    you want to reset the counter based on what, e.g., each chapter or each section, etc. please confirm that...
    – MadyYuvi
    Sep 12, 2019 at 13:22
  • very thank u!!!!
    – hohohaha
    Sep 12, 2019 at 13:43
  • I’m voting to close this question because it was solved in the comments. Mar 14, 2021 at 9:09

1 Answer 1

-1

What I came up with is this.: Its somewhat automatic so you do not have to watch your counter resets …

\documentclass[leqno]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{amsmath, amsthm}
\usepackage{mdframed}
%% Code by David Carlisle at https://tex.stackexchange.com/a/258575/38080
\makeatletter
\def\formatout#1{\hbox{\hskip1sp\m@th\llap{%
            \normalcolor\normalfont#1\hspace{1.0cm}}}}
\let\oldmaketag@@@\maketag@@@
\def\oldtagform@#1{\oldmaketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\oldtagform@{\ref{#1}}}}
\def\maketag@@@#1{\formatout{#1}}
%
% redefine the amsthm theorem start macro to use \formatout
%
\def\@begintheorem#1#2[#3]{%
    \deferred@thm@head{\the\thm@headfont \thm@indent
        \@ifempty{#1}{\let\thmname\@gobble}{\let\thmname\@iden}%
        \@ifempty{#2}{\let\thmnumber\@gobble}{\let\thmnumber\thmnumber}%
        \@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
        \thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
        \the\thm@headpunct
        \thmheadnl % possibly a newline.
        \hskip\thm@headsep
    }%
    \ignorespaces}%
\makeatother
\swapnumbers

\def\thmnumber#1{\formatout{(#1)}}
% https://tex.stackexchange.com/a/303245/38080
\newtheorem{thm}[equation]{Theorem}
\newtheorem{exa}[equation]{Example}

%%%%% New stuff here
\newcounter{threelabelcounter}
\usepackage{ifthen}
\newcommand{\countercheck}{
    \stepcounter{threelabelcounter}
    \ifthenelse{\thethreelabelcounter>2}{\setcounter{threelabelcounter}{0}}{}
    \setcounter{equation}{\thethreelabelcounter}
%\thethreelabelcounter
}
%%% until here...

\begin{document}
    
    Let's start with
    \begin{equation}
    E=mc^2
    \label{eq:mc2}
    \end{equation}
    \countercheck
    so we go to:
    
    \begin{equation}
    e
        \label{thE}
    \end{equation}
    \countercheck
    This leads to this
    
    \begin{equation}
 E
                \label{exE}
    \end{equation}
    \countercheck
    % innerleftmargin+leftmargin must be 0pt...
    \begin{mdframed}[backgroundcolor=gray!20, innerleftmargin=0pt, linewidth=0pt]
        Also
        \begin{equation}
        m=E/c^2
        \label{eq:mc2i}
        \end{equation}
    \end{mdframed}
    
    And the references are Eq.~\ref{eq:mc2}, Th.~\ref{thE}, Ex.~\ref{exE}.
    
\end{document}

Now somehow you have to get checkcounter to be executed when label is called. I had no luck with that yet.

Something like this could help in this case. Redefining the equation command or theorem command. Custom theorem numbering

Not the answer you're looking for? Browse other questions tagged .