2

I'm writing my math notes. A paragraph may include (or be followed as a separate paragraph) by an "Open question".

This is a paragraph making some points about a topic. Open question: Why is this true?

Open question: I don't understand why bla is bleah. Is this due to this or to that?

Is there a way to have something like an \openQuestion command to be used like in the following way?

This is a paragraph making some points about a topic. \openQuestion{Why is this true?}

\openQuestion{I don't understand why bla is bleah. Is this due to this or to that?}

In particular, I'd like the following features:

  1. all the questions listed together somewhere (possibly after the Table of Contents) in order of appearance
  2. each entry of the list has the page number at which the question is posed
  3. the page number is clickable (to move to the referenced page)
  4. the argument to the \openQuestion command also appears in the final layout where the command is called, exactly as it were normal text outside the command scope.

For now I tried to do this with imakeidx

\documentclass[11pt,a4paper]{book}
\usepackage{imakeidx}
\makeindex[name=firstIndexName,title=Title of the First Index,intoc,columns=1]
\usepackage{hyperref}

\begin{document}
\mainmatter
This is a paragraph making some points about a topic. Why is this true?\index[firstIndexName]{Why is this true?}

I don't understand why bla is bleah. Is this due to this or to that?\index[firstIndexName]{I don't understand why bla is bleah. Is this due to this or to that?}

\backmatter
\printindex[firstIndexName]

\end{document}

which outputs (the relevant part)

Output of the Open Questions list

Unfortunately, I can't achieve (see the numbered list above):

  1. "...in order of appearance". Instead the entries are sorted alphabetically.
  2. I have to write the question twice, once as argument to \index, once outside \index.
  • this might be accomplished by using one of the endnotes packages. (not tried) – barbara beeton Jun 7 '18 at 17:06
1

It is possible to use my rdfref package for such tasks. It enables us to define objects with properties, which can then be retrieved using simple query language. Rdfref isn't on CTAN, so you must install it by hand. I've also never wrote a documentation, but you can see other examples of use here or here.

I've created a simple package, openquestion.sty, with two commands, \openQuestion and \listQuestions. \openQuestion defines new object, set properties such as object type, text and page number, defines hyper targer and prints the question. \listQuestions uses simple query mechanism to process all questions and prints the question text together with link to the page number.

\ProvidesPackage{openquestion}
\RequirePackage{rdfref-user}
\RequirePackage{rdfref-query}
\RequirePackage{hyperref}

\newcommand\openQuestion[1]{%
  % define a new object, with anonymous name
  \BlankNode%
  % set basic object properties
  \AddProperty{rdf:type}{oq:question}%
  \AddProperty{oq:text}{#1}%
  \AddPropertyEx{doc:pageNo}{\thepage}%
  % define target for hyperlink, using the current object
  % name as label
  \hypertarget{\CurrentObject}{#1}%
}

\newcommand\listQuestions{%
  \enumerate%
  % process all objects with rdf:type oq:question
  \Bind{?obj}{rdf:type}{oq:question}{
    \edef\currobject{\GetVal{?obj}}% define current object for simpler access
  \item% make enumerate item
    \GetProperty{\currobject}{oq:text}\dotfill% print the question
    % print the page number with link to the page
  \hyperlink{\currobject}{\GetProperty{\currobject}{doc:pageNo}}}%
  \endenumerate%
}


\endinput

The most interesting part is the \Bind command. It can query the objects and their properties. It has four parameters, first three are used for searching of objects, properties and values, the fourth contains code which is executed for each matched value. It is possible to assign a variable using ?varname, its value can be then accessed using \GetVal{?varname} in the fourth parameter. In this example, we search for all objects with rdf:type property equal to oq:question, it was assigned in the \openQuestion command. The object name is then saved in the \currentobject macro for easier access and faster processing. The page number and text are then retrieved using \GetProperty commands.

A sample file:

\documentclass[11pt,a4paper]{book}
\usepackage{openquestion}
\usepackage{lipsum}

\begin{document}

\listQuestions

\lipsum

This is a paragraph making some points about a topic. Why is this true?\openQuestion{Why is this true?}

\lipsum[2-10]

I don't understand why bla is bleah. Is this due to this or to that?\openQuestion{I don't understand why bla is bleah. Is this due to this or to that?}


\end{document}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.