GeneralDelay output to another part

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
CutestPenguin
Posts: 4
Joined: Tue Jan 13, 2015 4:23 am

Delay output to another part

Post by CutestPenguin »

I have a question about LaTeX, I wanted to write something like a Puzzle book. I wanted to know what would be the best way to write it?
What I have in mind is a number of Puzzles in Part I, then hints in Part II and finally solutions in Part III. I want to name each problem once and I expect the hints and solution section of the PDF to automatically get named as problem hint and problem solution respectively.
I would also like functionality like being able to move back and forth between the problem and its hint/solution.

Recommended reading 2024:

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

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Delay output to another part

Post by Johannes_B »

Hi and welcome,

i'd love to help you, not only because of your user name, but i don't really know what you want to achieve.

Basically, you can do what you want using nameref. But i guess you want an advanced interface.
Maybe even package exsheets might be of help here.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
CutestPenguin
Posts: 4
Joined: Tue Jan 13, 2015 4:23 am

Delay output to another part

Post by CutestPenguin »

Hi Johannes,

Thank you very much for your help. I think the exsheets package might do it, though it will take me a while to understand it.

To clarify what I want to do, I have created a small LaTeX file, if you could have a look at it. Here is a https://www.overleaf.com/read/yzzwtxzbhjnq

I want to be able to do the same thing in a more sophisticated and structured manner. Can you suggest me something ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Delay output to another part

Post by Johannes_B »

The question has now been asked over at TeX.SX as well.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Delay output to another part

Post by cgnieder »

I'll add my answer from TeX.sx here as well.

With exsheets this can be done with not too much effort (with a slightly different syntax). The following code uses exsheets' question property mechanism and its programming facilities like ForEachQuestion or \ExSheetsHeading. The command \NewDocumentCommand is provided by xparse which is loaded by exsheets.

Code: Select all

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{exsheets}

\SetupExSheets{ headings = block-subtitle }

% new property `hint':
\DeclareQuestionProperty{hint}

% a command to print all given hints
\NewDocumentCommand\printquestionhints{}{%
  \ForEachQuestion
    {%
      \IfQuestionPropertyT{hint}{##1}{%
        \ExSheetsHeading
          {block}               % headings style
          {Hint}                % heading
          {\QuestionNumber{##1}}% number
          {0}                   % points -- need to be zero here
          {0}                   % bonus points -- need to be zero here
          {##1}%                % ID
        \GetQuestionProperty{hint}{##1}%
        \par
        \medskip
      }%
    }%
}

\begin{document}

\section{Problems}
\begin{question}[subtitle=Pythagoras]
  This is the first problem.
  \SetQuestionProperties{ hint = This is a hint to the first problem. }
\end{question}
\begin{solution}
  This is the solution to the first problem.
\end{solution}

\begin{question}[subtitle=Another Problem]
  This is the second problem.
\end{question}
\begin{solution}
  This is the solution to the second problem.
\end{solution}

\begin{question}[subtitle=Yet Another Problem]
  This is the third problem.
  \SetQuestionProperties{ hint = This is a hint to the third problem. }
\end{question}
\begin{solution}
  This is the solution to the third problem.
\end{solution}

\section{Hints}
\printquestionhints

\section{Solutions}
\printsolutions

\end{document}
Regards
site moderator & package author
Post Reply