2

Consider these statements

Exercise 1. $\phi(n)$ is multiplicative.

Exercise 2. By Exercise 1 we have $\phi(n)=\prod_{p|n}(1-1/p)$.

Suppose I want to cross refer Exercise 2 to Exercise 1 what command should I give??

I looked at various example on this site, but I am unable to understand anything. I tried

  • Exercise 1. \label{1} $\phi(n)$ is multiplicative

  • Exercise 2. By \ref{1} we have ..... but this doesn't work.

Kindly help.

  • To use the TeX/LaTeX \label-\ref cross-referencing system, you generally need a counter variable that's incremented automatically (usually via a \refstepcounter directive). Please tell us how the exercise list is constructed and how the counter is incremented. – Mico Jul 2 '16 at 8:15
  • @Mico Em. Exercise list is constructed using the \textbf{Exercise 1 } command, there is no listing as such :( – crskhr Jul 2 '16 at 8:19
  • 2
    If you set the number by hand, how is the computer program supposed to know that there even is a number to be referred to. You have to define an environment along with a suitable counter. And when labeling stuff, don't use numerical labels. It is the worst you can do. Do something like label{multiplicativePhi}. – Johannes_B Jul 2 '16 at 8:22
  • 2
    I looked at your profile, you are a member for four years and have asked 23 questions. Why don't you use proper marup for your questions and comments? – Johannes_B Jul 2 '16 at 8:23
  • 1
    @Mico: Both interpretations are correct, in my point of view -- if it's the same file \label is sufficient, of course! – user31729 Jul 2 '16 at 9:23
4

It looks to me like you should set up a semi-customized enumerated list environment. One way to do this is with the facilities of the enumitem package. In the following example, a new enumerated list called "exlist" is defined and its formatting, labeling, and cross-referencing properties are specified. That way, items in the list can be cross-referenced using the standard \label-\ref mechanism.

enter image description here

\documentclass{article}

\usepackage{enumitem} % for customized lists
\newlist{exlist}{enumerate}{1}
\setlist[exlist]{leftmargin=*,itemindent=*,
         label = \textbullet\ \bfseries Exercise \arabic*.,
         ref   = Exercise \arabic*}
\begin{document}

\begin{exlist}
\item \label{ex:mult} $\phi(n)$ is multiplicative. 
\item By \ref{ex:mult} we have $\phi(n)=\prod_{p|n}(1-1/p)$.
\end{exlist}

\end{document}
  • 1
    ...nice than mine! +1 (well, missing the Heinlein reference, but well...) – Rmano Jul 2 '16 at 9:12
2

I think the problem here is that you do not grok the concept of label-reference in LaTeX ☺.

You should have an automatic numbered thing to use the automatic referencing one --- otherwise it has no sense (if you fix the exercise to "1", you can use "1", no?). For example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\newlist{exercise}{enumerate}{10}
\setlist[exercise,1]{label=\arabic*.}
\begin{document}
Bla bla bla
\begin{exercise}
\item \label{ex:simple} first exercise here 
\item \label{ex:complex} let's build on exercise~\ref{ex:simple}...
\end{exercise}

If you solved the exercises~\ref{ex:simple} and~\ref{ex:complex}, then \dots

\end{document}

(This is just to give an idea, probably the theorems environments are better for this, or tcolorbox to have fancy ones. Even this should be adjusted to remove the "dot" on the references, which surely can be done...).

This will compile to:

enter image description here

and if you add a intermediate item as \item Hi, I though an intermediate here:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.