1

(I'm sorry for my bad english) I created an accountant to do an enumeration of questions for an exercise list. Eventually I would like to make a reference to a given exercise. But the \label and \ref commands are not working for me. Could someone help me?

\documentclass[a4paper,12pt]{report}
\usepackage{amsmath,amsfonts,amscd,bezier}%gislaine
\usepackage{amssymb}
\usepackage[dvips]{graphicx}
\usepackage{pdfsync}
\usepackage{color}
\usepackage{hyperref}

\newcounter{eq}
\refstepcounter{eq}
%\setcounter{eq}{1}
\newcommand{\eq}{{\noindent {\bf{\arabic{eq}}}} \addtocounter{eq}{1}{\hspace{-0.1cm{{.}}}} }
\newcommand{\eqz}{{\setcounter{eq}{1}} {{\arabic{eq}}} \addtocounter{eq}{1}\hspace{-0.1cm{{.}}}}
%%%%%%%%%%%%%%%%%%%%

\begin{document}
\pagestyle{myheadings} \thispagestyle{empty}

\eq \label{eq1} Let $X$ be such that....

\eq \label{eq2}In this exercise consider $Y=2$ ...

\eq \label{eq3} Consider, in exercise \ref{eq1} (I would like to see the issue number 1)

\eq Here, consider in exercise \ref{eq2} (I would like to see the issue number 2) $Y=3$...

\eq Here, consider in exercise \ref{eq3} (I would like to see the issue number 3) $Y=5$...

\end{document}
12
  • 4
    Please, do not use \bf which has been obsolete for at least 12-15 years, and try \textbf{text} or {\bfseries text}
    – Moriambar
    May 19, 2017 at 20:24
  • 2
    I see, but try and stop using it since it has some drawbacks (other than not being supported) e.g., wrong spacing
    – Moriambar
    May 19, 2017 at 20:43
  • 3
    Don't use pdfsync: it's invasive and very obsolete.
    – egreg
    May 19, 2017 at 20:53
  • 3
    \addtocounter{eq}{1} does what you want. But what you really want is \refstepcounter{eq}.
    – Johannes_B
    May 20, 2017 at 5:32
  • 2
    @Moura if I 1) remove \refstepcounter{eq} from your example 2) replace \addtocounter{eq}{1} with \refstepcounter{eq} in the definition of \eq I get working references. What exactly doesn't work for you?
    – cgnieder
    May 22, 2017 at 17:53

2 Answers 2

2

All you need is to create the counter, set it, set a reference name and then you can start to reference it.

Let me elaborate with a short example.

\documentclass{article}

\usepackage{environ, hyperref, cleveref}



 \newcounter{QuotCount}
 \setcounter{QuotCount}{0}
 %
 \NewEnviron{fquote}[3][0.8]{%
    \refstepcounter{QuotCount}%
    \par\vspace{0.5cm}\noindent
  \begin{tikzpicture} %\pbox[pos][height][inner-pos]{max-width}{text}
      \node[font=\large\bfseries](box){%
        \pbox{#1\linewidth}{\BODY \label{quot:#3}}};
                \node[inner sep=1pt,very thin,anchor=east,pink,font=\bfseries\fontsize{48}{48}\selectfont,yshift=-5pt]at(box.north west){``};
                 \node[inner sep=1pt,very thin,pink,anchor=west,font=\bfseries\fontsize{48}{48}\selectfont,yshift=-8pt,xshift=-2pt]at(box.south east){''};
                \node[inner sep=1pt,very thin,anchor=north west,gray,font=\small\sffamily]at(box.south west){\begin{minipage}[t][1cm][t]{0.8\linewidth}
                \ {#2}\end{minipage}};
   \end{tikzpicture}\par
}

 \crefname{QuotCount}{quote}{quotes}
 \Crefname{Quotcount}{Quote}{Quotes}

  \begin{document}
 \begin{hsquote}{Antoine de Saint-Exupéry}{adesigner}
 A designer knows that has has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.
 \end{hsquote}

 \Cref{quot:designer} is a quote on design used in the tufte-book.

\end{document}
1
  • 3
    The key point here is \refstepcounter -- that's not mentioned at all -- no \refstepcounter, no working cross-referencing (unless knowing internals about \@currentlabel
    – user31729
    May 19, 2017 at 20:32
1

There are already packages, so you might want to go with this:

\documentclass[a4paper,12pt]{report}
\usepackage{amsmath,amsfonts,amscd,bezier}
\usepackage{amssymb}
\usepackage{color}

%%%%%%%%%%%%%%%%%%%%

\usepackage[thref]{ntheorem}
\usepackage{cleveref}
\newtheorem{exercise}{Exercise}
\newtheorem{nonum}{}


\begin{document}


\begin{exercise}\label{ex:foo}
foo
\end{exercise}


\begin{exercise}\label{ex:bar}
bar
\end{exercise}

\begin{nonum}\label{noex:foo}
foo
\end{nonum}


\begin{nonum}\label{noex:bar}
bar
\end{nonum}

References: \cref{ex:foo}, \cref{ex:bar} and \Cref{ex:foo}. 

References: \cref{noex:foo}, \cref{noex:bar} and \Cref{noex:foo}. 

\end{document}

Here are some manuals: http://www.ctan.org/pkg/cleveref, http://www.ctan.org/pkg/ntheorem. Here is an alternative: http://www.ctan.org/pkg/theorem.

enter image description here

4
  • Thanks for your help, but I do not like the word exercise to appear, only number.
    – Moura
    May 19, 2017 at 20:44
  • @Moura: Please see my edits. May 19, 2017 at 20:48
  • I saw. Maybe I did not understand. I would not like to have exercise 1, exercise 2. Only 1, 2,
    – Moura
    May 19, 2017 at 20:53
  • 1
    @Moura: The recent change introduced the environments "nonum", and they only show the number, not "exercise". May 19, 2017 at 20:55

You must log in to answer this question.

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