0

I have been struggling to understand my latex preamble. I have listed my preamble below for others to see.

MWE

\documentclass[12pt, titlepage, oneside, a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[titletoc]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, graphicx, fancyhdr}
\usepackage{amsmath}
\usepackage{amsthm,algorithm,algorithmic,yhmath,enumitem,lscape}
\usepackage{subcaption}
\usepackage[mathscr]{euscript}
\DeclareMathAlphabet{\mathcal}{OMS}{cmsy}{m}{n}
\usepackage{float}
\usepackage{chngcntr}

\begin{document}
$\mathcal{L}$
\end{document}

My questions are:

Question 1: Using the package chngcntr should allow me to reset my counter using the command

\counterwithin*{equation}{chapter}

However, it does not do anything. I have to manually set counter to zero after every chapter.

Question 2: I want mathcal{} to have a certain format. Something like you have in \usepackage[mathscr]{euscript} or similar but even if I put this in preamble it does not do anything and I have the bad-looking \mathrsfs kind of thing. Additionally, I tried manually setting it using the command given in this link but I get conflict statement saying \mathcal is already defined**. How can I get this to work?

Added Information: As for the chngcntr package, I found that a newcommand added to preamble was causing a problem. Removing this and using a regular \chapter{} command indeed sets it according to chapter. But I need it because I do not want to see Chapter # written on top all the time. I would also like to understand the reason behind the problem.

\newcommand{\mychapter}[2]{
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}
\addcontentsline{toc}{chapter}{#2}}
Zero
  • 165
  • 4
    General rule here: One (!!!!) question, not a bunch of issues/requests. Please show us the compilable version of your document with the \counterwithin* issue. –  Jul 05 '16 at 09:40
  • 4
    apart from the fact that you haven't shown any example of your problem cases, equations are reset every chapter in the report class by default, so no declaration should be needed for that. – David Carlisle Jul 05 '16 at 10:28
  • Please take a look at the edited question. Thank you for responding! – Zero Jul 05 '16 at 17:03

2 Answers2

2

\setcounter{foo}{...} never resets counters on the reset list of the counter, i.e. \setcounter{chapter}{...} will not reset section, equation.

Apparently the number of the chapter is given manually here, so \setcounter{chapter}{\numexpr#1-1} is applied, i.e. subtracting 1 from the desired value. Then use \refstepcounter which does two things:

  • Providing the correct label information (if needed)
  • Calling \stepcounter which in turn guarantees reseting of the counters using the \@elt - mechanism and increasing the chapter counter again, having the requested value then.

\documentclass[12pt, titlepage, oneside, a4paper]{report}
\usepackage[T1]{fontenc}
%\usepackage[bitstream-charter]{mathdesign}
\usepackage[titletoc]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, graphicx, fancyhdr}
\usepackage{amsmath}
\usepackage{amsthm,algorithm,algorithmic,yhmath,enumitem,lscape}
\usepackage{subcaption}
%\usepackage[mathscr]{euscript}
\DeclareMathAlphabet{\mathcal}{OMS}{cmsy}{m}{n}
\usepackage{float}
\usepackage{chngcntr}


\newcommand{\mychapter}[2]{%
\setcounter{chapter}{\numexpr#1-1}%
\refstepcounter{chapter}%
\chapter*{#2}
\addcontentsline{toc}{chapter}{#2}}

\begin{document}
\tableofcontents

\mychapter{4}{Foo}

\begin{equation}
  E=mc^2 
\end{equation}

\begin{equation}
  E=mc^2 
\end{equation}

\mychapter{17}{Foobar}

\begin{equation}
  E=mc^2 
\end{equation}

\begin{equation}
  E=mc^2 
\end{equation}



\end{document}

This answer does not address the unrelated mathcal issue!

  • Thanks a lot for the information...it really helped. Unfortunately, I cannot mark your answer as accepted since I have another question that needs answer...keep up the good work :) – Zero Jul 19 '16 at 11:47
  • @Zero: Actually, if this answers only a part of your question you should accept it, regardless whether it's me or or somebody else answering you questions. Changing the question is not encouraged, neither is abandoning questions :-( –  Jul 19 '16 at 17:50
  • I apologize but I asked both questions together. I made edits but only to elaborate...I didn't add a new question...I am sure of asking them together because I got across the first problem by using setcntr command after every chapter...It was the second question that made me ask the question. So, I think the decision is fair...If you think not, I am here to see your response. :) – Zero Jul 19 '16 at 20:30
  • @Zero: Even if you did not ask another question: Don't ask two questions in the same post, that's another general rule here on TeX.SX! \mathcal does nothing have to do with the counter - issue –  Jul 19 '16 at 20:34
0

About question 2, I lost a day trying to figure out how to use the old \mathcal{} letters with the \usepackage[bitstream-charter]{mathdesign} option, and, the answer you linked by you-know-who (Two different calligraphic font styles in math mode) helped me in getting rid of the already defined error!

Altogether the solution for the second problem is the following (in preamble):

\usepackage{calrsfs}
\DeclareMathAlphabet{\pazocal}{OMS}{zplm}{m}{n}

\let\mathcal\undefined
\newcommand{\mathcal}[1]{\pazocal{#1}}
merosss
  • 101