I would like to have examples in my document look like this:
Section 2
(2.1) This is an example.
This is a reference to example (2.1).
That is:
- the section number appears both next to the example and in the reference to it
- both the labels and references to examples have brackets around them: I shouldn't have to do a whole lot of manual bracketing of \ref, i.e., not example (\ref{myexample}) for every single reference to every single example.
- have the example numbers reset to 1 at the beginning of each section
- ideally I want to use
cleverefin order to minimise typing too :)
So far the closest I've got is with the linguex package:
\documentclass{article}
\usepackage{linguex}
\renewcommand{\theExNo}{(\thesection.\arabic{ExNo})}
\usepackage{cleveref}
\crefname{ExNo}{example}{examples}
\let\oldsection\section
\renewcommand{\section}{\setcounter{ExNo}{0}\oldsection}
\begin{document}
\section{First section}
\ex. Example the first.\label{ex1}
I'd like to refer to \cref{ex1}.
\section{Second section}
\ex. Example the second.\label{ex2}
I'd like to refer to \cref{ex2}.
\end{document}
However the output of this looks like:
1 First section
(1) Example the first.
I’d like to refer to example (1.1).
2 Second section
(1) Example the second.
I’d like to refer to example (2.1).
That is, I've got the automatic bracketing in the references, the counter resetting, but the examples themselves are marked (1) rather than (1.1) and (2.1).
I am presently agnostic regarding the various linguistic example packages, so if you know how to make this work with a different one, I would be grateful for that too.