2

I am writing a mathematics book. For each example, I would like to store a few attributes, including:

-The source

-Whether I have checked the problem

-The difficulty of the problem

(etc.)

Normally, I would just create a spreadsheet that would do this, but I frequently rearrange the examples, making it cumbersome to update the spreadsheet.

Is it possible to create a database that stores these attributes for each \item (each example), that can be conveniently printed, and dynamically updated when the \item's are rearranged?

Here's a tangible example of what I want.

\section{Chapter 1}

\begin{enumerate}

%Source: X
%Checked: No
%Difficulty: Easy
\item (Example goes here)

%Source: Y
%Checked: Yes
%Difficulty: Hard
\item (Example goes here)
\end{enumerate}

And the output would be a .PDF, something like

Example 1.1

Source: X
Checked: No
Difficulty: Easy

Example 1.2
Source: Y
Checked: Yes
Difficulty: Hard

where the above is formatted in a table of some sort.

Thanks in advance for the help! Please let me know if I should clarify the question.

  • You have such a database: Labels and references, however, it requires some work to organize still –  Aug 01 '14 at 21:02

1 Answers1

1

You can easily create a command that writes the information to a file. This probably needs some customisation, but it does essentially what you need.

\documentclass{article}

\makeatletter
\newwrite\@datawrite
\immediate\openout\@datawrite=\jobname.data

\newcommand\exampledata[3]{%  
\immediate\write\@datawrite{Example \thesection.\theenumi}
\immediate\write\@datawrite{Source: #1}
\immediate\write\@datawrite{Checked: #2}
\immediate\write\@datawrite{Difficulty: #3}
\immediate\write\@datawrite{}}

\AtEndDocument{\closeout\@datawrite}

\makeatother

\begin{document}
\section{A section}

\begin{enumerate}
\item
\exampledata{A nice book}{yes}{easy}
Show that $a=b$.
\item
\exampledata{Another nice book}{no}{impossible}
Show that $c=d$
\end{enumerate}

\end{document}

After compiling, the .data file contains the following:

Example 1.1
Source: A nice book
Checked: yes
Difficulty: easy

Example 1.2
Source: Another nice book
Checked: no
Difficulty: impossible

Edit

To get a pdf, just add some extra \immediate\write commands to add a LaTeX preamble and \end{document}, and some formatting instructions for each entry.

Ian Thompson
  • 43,767