GeneralEnvironment to list content

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jc_tex
Posts: 3
Joined: Sun Sep 12, 2010 5:04 pm

Environment to list content

Post by jc_tex »

I would like to use an “environment” or some form of command that would achieve the following:
There would be 5 fields:
• Question (could be a paragraph or more text with formulas, tables,…)
• Author (less than 128 characters)
• Title (less than 128 characters)
• Tag (open of closed, so binary)
• Optional field for answer (could be a paragraph or more,…)
Then I would be able to call this environment anywhere in my documents.
In addition I’d like to be able to make a list of (open) questions with titles like a list of figures for instance.
Any ideas where I could find something like that? Or how to create it?
Thanks
Last edited by jc_tex on Sun Sep 12, 2010 10:52 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.

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

Re: Environment to list content

Post by gmedina »

Hi,

and the format for the arguments in the final document? Please describe the desired final layout for "Question", "Author", "Title", "Tag" and "Answer".
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jc_tex
Posts: 3
Joined: Sun Sep 12, 2010 5:04 pm

Environment to list content

Post by jc_tex »

Hi,

It would look like

Question 2.3. -- Short title (Closed) %in bold, and that would be the third question in chap 2.
This is the text for the main question.
My name, Sept 1st 2010
Answer 2.3.
This is the answer of the question.
Other name, Sept 12th 2010

And then I'd like the ability to list all (open or not) question titles at the beginning of the document.

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

Environment to list content

Post by gmedina »

I think it's better to have two environments: one for the questions and the other one for the answers. The following code will give you some ideas:

Code: Select all

\documentclass{book} 
\usepackage{tocloft}

\newcommand{\listquestionname}{List of Questions}
\newlistof[chapter]{question}{qst}{\listquestionname}

\newsavebox\mybox

\newenvironment{Myquestion}[3]
  {\refstepcounter{question}%
    \addcontentsline{qst}{question}{\protect\numberline{\thequestion} #1}
    \medskip\noindent{\bfseries Question~\thequestion--#1 (#2)}\\\textit{#3}\\%
  }
  {\par}
\newenvironment{Myanswer}[1]
  {\sbox\mybox{\textit{#1}}
    \par\noindent{\bfseries Answer~\thequestion}\\%
  }
  {\\\usebox\mybox\par}

\begin{document}
\listofquestion

\chapter{Test chapter}

\begin{Myquestion}{Short title}{Closed}{My name, Sept. 1st 2010}
The text of the question goes here.
\end{Myquestion}
\begin{Myanswer}{Other name, Sept. 12th 2010}
The text of the answer goes here.
\end{Myanswer}

\begin{Myquestion}{Short title}{Open}{My name, Sept. 1st 2010}
The text of the question goes here.
\end{Myquestion}

\chapter{Test chapter two}

\begin{Myquestion}{Short title}{Open}{My name, Sept. 2nd 2010}
The text of the question goes here.
\end{Myquestion}

\end{document} 
Of course, feel free to adapt my example to meet your needs.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jc_tex
Posts: 3
Joined: Sun Sep 12, 2010 5:04 pm

Re: Environment to list content

Post by jc_tex »

Thank you very much gmedina, that's what I needed.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Environment to list content

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic accordingly as clearly written in Section 3 of the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
Post Reply