2

I started using the ShareLateX Basic Homework Template:

https://www.sharelatex.com/templates/examples/basic-homework-template

in which are defined the 'problem' and 'solution' environments, defined by

\newenvironment{solution}[2][Solution]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

Using the 'align' environment, the equations are numbered as (1), (2), etc. However, I would like the equations to be numbered based on which problem and associated solution that they are inside of. That is, I would like them to be numbered as (problem#.equation#) and (solution#.equation#).

For example, the second equation in the first problem/solution would be (1.2). Unfortunately I cannot find any resource which gives me any guidance on this.

1
  • Welcome to TeX SX! Could you post a full , yet minimal, compilable code?
    – Bernard
    Jul 21, 2018 at 19:19

1 Answer 1

2

Just replace the \newenvironment{problem} lines with

\newenvironment{problem}[2][Problem]{\stepcounter{myproblemcnt}\setcounter{myproblemcnt}{#2}\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

and add

\makeatletter
\renewcommand{\theequation}{\arabic{myproblemcnt}.\arabic{equation}}
\newcounter{myproblemcnt}
\@addtoreset{equation}{myproblemcnt}
\makeatother

to your preamble.

Full MWE:

\documentclass[12pt]{article}

\usepackage{answers}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{mathrsfs}
\usepackage[margin=1in]{geometry} 
\usepackage{amsmath,amsthm,amssymb}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\R}{\mathbb{R}}

\DeclareMathOperator{\sech}{sech}
\DeclareMathOperator{\csch}{csch}

\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{definition}[2][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{proposition}[2][Proposition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{solution}[2][Solution]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\newenvironment{problem}[2][Problem]{\stepcounter{myproblemcnt}\setcounter{myproblemcnt}{#2}\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

\makeatletter
\renewcommand{\theequation}{\arabic{myproblemcnt}.\arabic{equation}}
\newcounter{myproblemcnt}
\@addtoreset{equation}{myproblemcnt}
\makeatother

\begin{document}

% --------------------------------------------------------------
%                         Start here
% --------------------------------------------------------------

\title{Weekly Homework Template Tutorial}%replace with the appropriate homework number
\author{Your Name\\ %replace with your name
Course-Semester} %if necessary, replace with your course title

\maketitle
%Below is an example of the problem environment
\begin{problem}{6}
text.
\end{problem}

%Below is the solution environment
\begin{solution}{}
\begin{align}
a\\b\\c
\end{align}
\end{solution}

%Below is an example of the problem environment
\begin{problem}{13}
    text.
\end{problem}

%Below is the solution environment
\begin{solution}{}
\begin{align}
a\\b\\c
\end{align}
\end{solution}


\end{document}

result

0

You must log in to answer this question.

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