GeneralTrying to creating a new environment with its own list

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jonysatie
Posts: 27
Joined: Fri Apr 06, 2007 1:15 am

Trying to creating a new environment with its own list

Post by jonysatie »

Hi Everyone, how are you.

I'm trying to make since two days a new environment it order to include explicit
examples in a document. The problem is that I would like to make a list of all these environments that I have included and the result is a chaotic horizontal list.
I'm sure that you can help me. Again.
Please could you tell me what's wrong and how can I fix it?
Thank you very much.

PD: I have attached the .tex (compiling on latex->ps->pdf is required)
Attachments
nuevosentornos.tex
(3.26 KiB) Downloaded 238 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Trying to creating a new environment with its own list

Post by localghost »

The addition of an example to your LoL should take place outside the shaded environment. Moreover it seems that the \par command need to be added to ech line. Modify your declaration as follows.

Code: Select all

\newenvironment{ejemplo}[1]{%
  \refstepcounter{ejem}
  \begin{shaded}
    \textbf{Ejemplo. \theejem. #1}\par
}{%
  \end{shaded}
  \addcontentsline{lol}{ejemplo}{\protect\numberline{\theejem} #1\par}
}
I didn't test it so there's no guarantee.


Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
jonysatie
Posts: 27
Joined: Fri Apr 06, 2007 1:15 am

Re: Trying to creating a new environment with its own list

Post by jonysatie »

Thanks but I think that I have now 9 errors. So there's some kind of mistake in this code. This time I'm very lost with the solution of my problem. I would thank any help.

PD: I include de new example (with logalghost's modification)
Attachments
nuevosentornos2.tex
(3.42 KiB) Downloaded 257 times
Last edited by jonysatie on Sat Oct 10, 2009 1:32 am, edited 1 time in total.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Trying to creating a new environment with its own list

Post by gmedina »

Hi,

the problem comes from this:
localghost wrote:...
\newenvironment{ejemplo}[1]{%
\refstepcounter{ejem}
\begin{shaded}
\textbf{Ejemplo. \theejem. #1}\par
}{%
\end{shaded}
\addcontentsline{lol}{ejemplo}{\protect\numberline{\theejem} #1\par}
}...
no parameters can be used explicitly in the ending part of the definition of a new environment. In some time (when I take a look at the code you posted) I can give you some possible solution.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jonysatie
Posts: 27
Joined: Fri Apr 06, 2007 1:15 am

Re: Trying to creating a new environment with its own list

Post by jonysatie »

Ohh thanks .. So I will be waiting for your post.
There's a few helpfull Tips here: http://www.golatex.de/newenvironment-t3238.html
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Trying to creating a new environment with its own list

Post by gmedina »

Hi again,

the following code can be used as a starting point to obtain what you desire:

Code: Select all

\documentclass[12pt]{memoir}
\usepackage{xcolor}
\usepackage{amsmath}

\definecolor{shadecolor}{gray}{0.9} 
\newcounter{ejem}
\numberwithin{ejem}{section}

\makeatletter
  \newcommand\l@ejemplo{\@dottedtocline{1}{2em}{3em}}
\makeatother

\newlistof{listofexamples}{lol}{Lista de Ejemplos}

\newenvironment{ejemplo}[1]{%
  \refstepcounter{ejem}
  \begin{shaded}
    \addcontentsline{lol}{ejemplo}{\protect\numberline{\theejem} #1}
    \textbf{Ejemplo \theejem. #1}\par}
  {\end{shaded}}

\begin{document}
\listofexamples

\chapter{veamos}

\section{lalalala}

\begin{ejemplo}{mosh}
  Hola me llamo Jonathan y soy feliz adem\'as de entusiasta.
\end{ejemplo}

\subsection{Veamos de nuevo}

\begin{ejemplo}{mish}
  Hola me llamo Jonathan y soy feliz adem\'as de entusiasta y contento.
\end{ejemplo}

\section{lalalala}

\begin{ejemplo}{lin}
  Hola me llamo Jonathan y soy feliz.
\end{ejemplo}

\begin{ejemplo}{hallo}
  Hola me llamo Jonathan y soy m\'as feliz a\'un.
\label{ejem:jojo}
\end{ejemplo}

Ver ejemplo \ref{ejem:jojo}

\end{document}
Please, feel free to adapt my example according to your needs.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jonysatie
Posts: 27
Joined: Fri Apr 06, 2007 1:15 am

Trying to creating a new environment with its own list

Post by jonysatie »

Ohh that's indeed what I was searching for.
Could you explain just a little what this commands mean.

Code: Select all

\makeatletter
  \newcommand\l@ejemplo{\@dottedtocline{1}{2em}{3em}}
\makeatother
And thank you. This solved the problem.
Bye
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Trying to creating a new environment with its own list

Post by gmedina »

jonysatie wrote:...
Could you explain just a little what this commands means.

Code: Select all

\makeatletter
  \newcommand\l@ejemplo{\@dottedtocline{1}{2em}{3em}}
\makeatother
Of course. The \l@ejemplo command does the actual typesetting of the entries in the newly defined LoL (List of Examples); in my example code I used the \@dottedtocline command to control the entries layout.

The \@dottedtocline command has the following syntax:

Code: Select all

\@dottedtocline{level}{indent}{numwidth}{text}{page}
The meaning of the five parameters is the following:

level: the nesting level of the entry.
indent: the total indentation from the left margin.
numwidth: the width of the box that contains the number.
text: the text to be used following the number of the entry.
page: the page number in the document in which the entry will actually appear.

In my example I used only the first three parameters, since the other two will be picked automatically when using the \addcontentsline command.

The \makeatletter and \makeatother commands make possible to use the special character @ in the definition or redefinition of new commands or environments.
jonysatie wrote:...
And thank you. This solved the problem.
Bye
You are welcome!
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply