Text FormattingReferences for custom list environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jmtuley
Posts: 6
Joined: Tue Sep 22, 2009 4:57 am

References for custom list environment

Post by jmtuley »

Hello,

I am working on an environment for axiom lists. The end result should look something like:

Code: Select all

\begin{axiomlist}[AMon]
\item Axiom 1 \label{axm:test}
\item Axiom 2
\item Axiom 3
\end{axiomlist}
which should produce output like
(AMon1) Axiom 1
(AMon2) Axiom 2
(AMon3) Axiom 3
I have that much:

Code: Select all

\newcounter{axmctr}

\newcommand{\axmnum}{\arabic{axmctr}}
\newenvironment{axiomlist}[1][Axm]
{
\begin{list}{\textbf{(#1\axmnum)}}{\usecounter{axmctr}}
}%
{
\end{list}
}
Where I'm stuck is producing good output for \ref. Obviously, the default behavior is to give just the value of the counter. I need it to produce (in the above example) "AMon1". This needs to be resilient to having multiple axiomlist environments with different "tags"; each reference should be tagged properly.

So far, I've looked into the cleverref and varioref packages; neither seems to have the capability to do this localized re-tagging. (On the other hand, maybe I missed something.) The enumerate package would have done the custom list, but is also deficient in the reference department (and I don't need the full power of that package, just this specific and oft-reused environment).

Thanks in advance,
--John.
Last edited by jmtuley on Wed Sep 22, 2010 9:25 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

References for custom list environment

Post by gmedina »

Hi, Jhon

you could use the enumitem package; a little example:

Code: Select all

\documentclass{article}
\usepackage{enumitem}

\newlist{Axiom}{enumerate}{10}
\setlist[Axiom]{label=\textbf{(AMon\arabic*)},ref=AMon\arabic*,leftmargin=*}

\begin{document}

\begin{Axiom}
  \item Axiom 1.\label{axi:one}
  \item Axiom 2.
  \item Axiom 3.
\end{Axiom}

As we can see in~\ref{axi:one}...

\end{document}

1,1,2,3,5,8,13,21,34,55,89,144,233,...
jmtuley
Posts: 6
Joined: Tue Sep 22, 2009 4:57 am

References for custom list environment

Post by jmtuley »

gmedina wrote:Hi, Jhon

you could use the enumitem package; a little example:
That was very helpful and a great start for me; unfortunately, not sufficient: I need to write a self-contained (or reliant only on standard packages) package/class to give to authors, to maintain consistency of style across a particular project. Unfortunately, the code for enunitem is a bit over my head, and I'm having difficulty puzzling out which bit does what I need. I guess I need to keep looking at it until it makes more sense.

Thanks gmedina!
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

References for custom list environment

Post by gmedina »

You could simply redefine the commands controlling the label (\labelenumi) and the reference representation (\p@enumi) of a standard enumerate environment; something along these lines:

Code: Select all

\documentclass{article}

\makeatletter
\newenvironment{Axiom}
  {\renewcommand\labelenumi{\bfseries (AMon\theenumi)}%
    \renewcommand\p@enumi{AMon}%
    \begin{enumerate}%
    \addtolength{\itemindent}{2.5em}
  }
  {\end{enumerate}}
\makeatother

\begin{document}

\begin{Axiom}
  \item Axiom 1. \label{axi:one}
  \item Axiom 2.
\end{Axiom}

As we can see in~\ref{axi:one}...

\end{document}
Of course, you don't have to use \makeatletter nor \makeatother in a .cls or in a .sty file.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jmtuley
Posts: 6
Joined: Tue Sep 22, 2009 4:57 am

Re: References for custom list environment

Post by jmtuley »

That's exactly what I was looking for! I was a little worried when you started changing standard labels, but everything seems to work out fine (even with multiple Axiom environments and an enumerate thrown in). Of course you knew that, but it's good to verify.

Thanks a lot!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

References for custom list environment

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic accordingly as clearly written in the Board Rules (to be read before posting). Please keep that in mind for the future so that a reminder will not necessary any more.


Best regards
Thorsten
Post Reply