21

I am creating multiple versions of a document from a single LaTeX source. Specifically, I have a series of lessons that have an instructor version (with notes and answers) and a plain student version. I am using the optional package to conditionally print the instructor's notes, following the basic methods outlined here: http://www.latex-community.org/forum/viewtopic.php?f=5&t=2060. And it works well. All I have to do is set a single flag.

My problem is this: the instructor's notes are often very long--too long to make marginal notes feasible. That means the pagination is different in the instructor and student versions of the document.

If possible, I would like to automatically place references to the student-edition pagination as marginal notes in the instructor edition. [Edit: To clarify: I would like this note to appear next to the line in the instructor's edition that corresponds to the top of a page in the student's edition, rather than inserting references to a page number at predetermined points in the instructor's version, such as at a section heading.] To create such notes currently, I have to generate a final version of the student edition and manually add notes at the right place for the instructor edition, a process that is time-consuming, prone to error, and brittle, as any revisions are likely to invalidate the old pagination.

This is not an ordinary external cross-referencing problem because I'm not setting a label at a fixed point ahead of time. I presume what I would need to do is process the student edition, write out the context of the page break that LaTeX has calculated to an auxiliary file, and process that information when creating the instructor's edition.

I haven't found any packages that address this problem, so I'm looking for any guidance as to how to tackle it. Is there anything I can hook into in the aux file that will give me this information? I don't know enough about LaTeX/TeX internals to even know where to start looking.

[Edit 2: The following is an expanded mwe that manually places the page-number marginal note where is belongs:]

\documentclass{article}
% change option to either 'student' or 'instructor'
%\usepackage[student]{optional}
\usepackage[instructor]{optional}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{marginnote}
\newmdenv[linewidth=1pt, roundcorner=5pt, leftmargin=10, rightmargin=10,%
    innertopmargin=\topskip]{instructorstyle}

\newcommand{\instructornote}[1]{
\opt{instructor}{%
\begin{instructorstyle}
\textsf{#1}
\end{instructorstyle}
}
}

\usepackage{lipsum}
\begin{document}

\lipsum[1]

\instructornote{The first note. \lipsum[2]}

\lipsum[3]

\instructornote{Another short note.}

\lipsum[5]

The page break in the student edition will occur in the middle of the following verse:

\begin{verse}
Whan that Aprille with his shoures soote    \\
The droghte of Marche hath perced to the roote, \\
And bathed every veyne in swich licour,\\
Of which vertu engendred is the flour;\\
Whan Zephirus eek with his swete breeth\\
Inspired hath in every holt and heeth\\
The tendre croppes, and the yonge sonne\\
Hath in the Ram his halfe cours y-ronne,\\
And smale fowles maken melodye,\\
That slepen al the night with open ye,\\
(So priketh hem nature in hir corages:\\
Than longen folk to goon on pilgrimages,\\
\opt{instructor}{\marginnote{\fbox{\textsf{---Page 2---}}}}
And palmers for to seken straunge strondes,\\
To ferne halwes, couthe in sondry londes;\\
And specially, from every shires ende\\
Of Engelond, to Caunterbury they wende,\\
The holy blisful martir for to seke,\\
That hem hath holpen, whan that they were seke.\\
\end{verse}

\lipsum[6]

\end{document}

enter image description here

[Edit 3: After all the helpful discussion, and a day spent trying to learn about \box255 and \shipout, I ran across references to LuaTeX callbacks, which may give access to the information I need to place the page-number callouts correctly. See Three things you can do with LuaTeX that would be extremely painful otherwise. Perhaps this is the way to go. Now I just need to learn Lua.]

13
  • Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – Adam Liter
    Commented Feb 17, 2014 at 7:21
  • I added an example, although I'm not sure how helpful it will be, as my question was more general than just a specific coding instance.
    – Karl Hagen
    Commented Feb 17, 2014 at 13:35
  • I solved a similar problem. My instructors manual contains just the instructor material in the source file, with page number references to the student version. It doesn't have the full student version text. I can post the macros as an answer if you think it might help. Commented Feb 17, 2014 at 13:58
  • 2
    @EthanBolker: if you're calculating page references on-the-fly when you make the student edition, that's exactly what I'm looking for. How the instructor material is divided between files seems a secondary issue.
    – Karl Hagen
    Commented Feb 17, 2014 at 15:49
  • 1
    @barbarabeeton: the problem with that approach is that I'm not looking to reference specific information. I want a note that effectively says "page n in the student edition starts here." That way, an instructor can look at his or her edition in class and direct students to the appropriate page in their version.
    – Karl Hagen
    Commented Feb 17, 2014 at 15:53

5 Answers 5

9
+100

I am extending the solution presented by @Ethan Bolker. I just put some hooks and reworked the environments to produce all the output from a single file.

I think that this is more manageable than having several files. Moreover, this solution will compile the students (main file) and the instructors one (defined inside with the macro \instructorMainFile).

Also, this version fixes the gobbled letters from the teacher environment, as it won't redefine it. Instead, we just need to redefine the final Teachers inside the instructors definition.

Additionally, when you execute the main file you need to pass the option --shel-escape to be able to compile the \instructorMainFile from within. Another option is to disable that part (by removing the hook at the end of document) and run it manually. In that case, you need to set the macro \instructorFileName inside of the produced by the filecontents.

\documentclass[pdftex,10pt]{book}
\usepackage{answers}
\usepackage{etoolbox}

\usepackage{filecontents}

% Our definition for file names
\newcommand{\instructorFileName}{notesfromtext}
\newcommand{\instructorMainFileName}{teachers}

\begin{filecontents}{\instructorMainFileName.tex}
\documentclass{book}
% we need this definition inside the instructor files
\newenvironment{Teacher}[1]{\par}{}
\begin{document}
% here goes your instructor info
\chapter{Teacher Manual}
This is the instructor's manual.

The pages that follow offer comments on the text,  pedagogical tips
and suggestions for the class.
It's generated from the \TeX{} source so that we can edit it where
it's relevant. When page numbers there change the page references here
change too.

\input{\instructorFileName.tex}
\end{document}
\end{filecontents}

% in document, connect instructorfile hook to \instructorFileName
\Newassociation{teacher}{Teacher}{\instructorFileName}
% we don't need to fix the labels or the environment, as we replaced it on the instructor definition
%\renewcommand{\Teacherlabel}[1]{}

\newcommand{\teacherhook}{%
\Writetofile{\instructorFileName}{
  \vspace{10pt}
  \par
  \textbf{Chapter \arabic{chapter},~ page~\arabic{page}}
}
% optional:
% point to instructor's manual from student version
\footnote{See comment in instructor's manual.}  
}

% lets patch the teacher environment created by the answers package
\BeforeBeginEnvironment{teacher}{\teacherhook}%

% you can replace this and compile by hand
% but I think the main idea is to use it all in one pass
% due to this you need to run your main document with --shell-escape
\def\mywrite{\unexpanded{\immediate\write18{pdflatex --jobname=\instructorMainFileName\space -interaction=nonstopmode '\noexpand\def\noexpand\instructorFileName{\instructorFileName}\noexpand \input{\instructorMainFileName}'}}}

% and hook it at the end of the document nicely
\AfterEndDocument{\mywrite}

% Here starts your writing
\Opensolutionfile{\instructorFileName}
\begin{document}

\chapter{Pythagoras and Euclid}

In this chapter we will show that the Pythagorean Theorem is
equivalent to the Parallel Postulate.
\begin{teacher}
xxxxx This is subtle. You will have to go over it slowly.

Note. This comment begins ``xxxxx'' to show that the first few
characters have been gobbled up in the instructor's manual. I fixed
this for my document but it seems to be broken here. I may have time
to fix it here some day. 
\end{teacher}

\chapter{Hyperbolic Geometry}

When there are multiple lines through a point parallel to a given
line, similar triangles are congruent!
\begin{teacher}
This is subtle too. 
\end{teacher}

\Closesolutionfile{\instructorFileName}

\end{document}

Edit

After the edit of OP, I change it to convert the sections into marginnotes. The idea is the same, you just need to be careful on the macro that you write to the instructors file, as the macros need to be \protected (and when I tested using several macros the \protect messed it up). One solution is to wrap them in one macro that get expanded, if you want some other solution it will be good idea to ask a separate question regarding that.

So, in the final instructor file (I renamed it to something more suited \instructorFileName) you need to code the behavior of the environment and the macro. In here, I used marginnote. Since now, the reference is sorted in \instRef before each Teacher environment you can use it as you please in other scenarios. Remember that all the information is store in \instructorAnswersFileName that is created on the fly from the students original file.

The output looks like this:

enter image description here

And the code is:

\documentclass[pdftex,10pt]{book}
\usepackage{answers}
\usepackage{etoolbox}

\usepackage{filecontents}

% Our definition for file names
\newcommand{\instructorAnswersFileName}{notesfromtext}
\newcommand{\instructorFileName}{teachers}

% The instructor file
\begin{filecontents}{\instructorFileName.tex}
\documentclass{book}
% package for the margin notes
\usepackage{marginnote}

% we need a command to handle the references (this is the command that will be called from
% the main student file), and here we make the definition to insert it
\newcommand{\definstRef}[1]{\def\instRef{#1}}

% we need this definition inside the instructor files
\newenvironment{Teacher}[1]{\par\marginnote{\instRef}}{}

\begin{document}
% here goes your instructor info
\chapter{Teacher Manual}
This is the instructor's manual.

The pages that follow offer comments on the text,  pedagogical tips
and suggestions for the class.
It's generated from the \TeX{} source so that we can edit it where
it's relevant. When page numbers there change the page references here
change too.

\input{\instructorAnswersFileName.tex}
\end{document}
\end{filecontents}

% in document, connect instructorfile hook to \instructorAnswersFileName
\Newassociation{teacher}{Teacher}{\instructorAnswersFileName}
% we don't need to fix the labels or the environment, as we replaced it on the instructor definition
%\renewcommand{\Teacherlabel}[1]{}

% we need to write the macro for the definition to be used in the instructor file
% note that we need to protect it so it is not expanded
% I tried to use compound macros, but the \protect in between gets messy, so just wrap them
% around just one macro for simplicity
\newcommand{\teacherhook}{%
\Writetofile{\instructorAnswersFileName}{%
\protect\definstRef{Chapter \arabic{chapter},~ page~\arabic{page}}
}
% optional:
% point to instructor's manual from student version
\footnote{See comment in instructor's manual.}  
}

% lets patch the teacher environment created by the answers package
\BeforeBeginEnvironment{teacher}{\teacherhook}%

% you can replace this and compile by hand
% but I think the main idea is to use it all in one pass
% due to this you need to run your main document with --shell-escape
\def\mywrite{\unexpanded{\immediate\write18{pdflatex --jobname=\instructorFileName\space -interaction=nonstopmode '\noexpand\def\noexpand\instructorAnswersFileName{\instructorAnswersFileName}\noexpand \input{\instructorFileName}'}}}

% and hook it at the end of the document nicely
\AfterEndDocument{\mywrite}

% Here starts your writing
\Opensolutionfile{\instructorAnswersFileName}
\begin{document}

\chapter{Pythagoras and Euclid}

In this chapter we will show that the Pythagorean Theorem is
equivalent to the Parallel Postulate.
\begin{teacher}
This is subtle. You will have to go over it slowly.
\end{teacher}

\chapter{Hyperbolic Geometry}

When there are multiple lines through a point parallel to a given
line, similar triangles are congruent!
\begin{teacher}
This is subtle too.
\end{teacher}

\Closesolutionfile{\instructorAnswersFileName}
\end{document}
3
  • 1
    Nice improvements. I'll use your \teacherhook. Commented Apr 16, 2015 at 14:08
  • it miss \newcommand{\instructorAnswersFileName}{notesfromtext} in filecontents environment no?
    – touhami
    Commented Apr 16, 2015 at 19:04
  • You can define it manually (as explained in the first part), or you can pass it to the file when you compile it. In both examples, the \instructorAnswersFileName is defined in the write18 in the \def\noexpand\instructorAnswersFileName{\instructorAnswersFileName} part.
    – adn
    Commented Apr 16, 2015 at 19:14
6

Context

Since the edit, it seems that what OP requested is different from the given answers.

This is a totally different approach. This one assumes that you want the same file (for the instructors and students), but the instructor version has more information than the students file. (Please correct this assumption. If that is what you need, the other solution can be discarded.)

Solution

This solution uses an auxiliary file \jobname.pages to store line by line the pages issued by the command \instructornote. Then, you need to run the file once for student (with that option turned on), and then with instructor (changing the option to instructor).

Results

  • Instructor: enter image description here

  • Student: enter image description here

Code

\documentclass{article}
% change the option accordingly (run first as student, and then as instructor)
\usepackage[student]{optional}
%\usepackage[instructor]{optional}

\usepackage{marginnote}


% here we save our auxiliary file
\opt{student}{%
  \newwrite\pagesfile
  \openout\pagesfile=\jobname.pages
}
\opt{instructor}{%
  \newread\pagesfile
  \openin\pagesfile=\jobname.pages
}

% The command writes and reads depending on the option
\newcommand{\instructornote}[1]{
% in student mode lets write it
\opt{student}{
  \write\pagesfile{Page~\thepage}
}
\opt{instructor}{
\read\pagesfile to\data
\marginnote{\data}
#1
}
}

% default behavior



\begin{document}

\section{Pythagoras and Euclid}

In this chapter we will show that the Pythagorean Theorem is
equivalent to the Parallel Postulate.

\instructornote{This is subtle. You will have to go over it slowly.}


\section{Hyperbolic Geometry}

When there are multiple lines through a point parallel to a given
line, similar triangles are congruent!
\instructornote{This is subtle too.}

\end{document}

Improvements

Note that the file is not verified in the \instructornote macro. Thus, a more robust solution will involve checking for the existence of the file, and handling it. For example, changing the behavior of the macro to insert some text to tell the instructor to run student option first, and then the instructor one.

Check TeXbyTopic Chapter 30 for more information on the auxiliary files handling. For example, check What is the basic mechanism for writing something to an aux file?.

5
  • Although this produces something somewhat different from what I'd requested, I like this approach a lot. It's elegant and easy to understand. It may not be optimally usable for my teachers, but this may wind up being the way to go. I was thinking, however, would it be possible, on the student-edition run, to write everything out to the file and use a hook like \AddEverypageHook (or \EveryShipOut from the everyshi package) to insert the \marginnote in the stream. Then when the instructor version is compiled, it takes all the text from that file we've just written?
    – Karl Hagen
    Commented Apr 17, 2015 at 20:18
  • Do you want to run both options on one pass? or do you want something else? If is the former, you can adapt a solution similar to my other approach, and compile it within the same doc using write18 and calling it from there. Another option, is to create a makefile and put the options from there and compile both documents in one run. If you need something else, please clarify your question because I thought that this was more closely related to your needs than the previous answer. However, now I am lost on what is what you really need.
    – adn
    Commented Apr 17, 2015 at 20:24
  • I don't mind two passes. I'm thinking about where the note goes. The difference between both approaches and what I'm asking for is that in yours, a page note appears at each instructor's note. What I had in mind is that the instructor's version contains the student text as well as notes, which are visually set off from the student text by frameboxes and a font change). Ideally, the page note would appear at the point in the text where there's a new page in the student edition. That means that it should be aligned with the text that appears in both versions rather than the instructor's note.
    – Karl Hagen
    Commented Apr 17, 2015 at 20:54
  • 1
    What would be better is that you create a minimal working example (MWE) showing the expected behavior for the instructor and student files by hand. That is, use the \opt macro to show what you expect to see in each version of the file. Then, it will be easier to automatize it.
    – adn
    Commented Apr 18, 2015 at 19:44
  • I expanded the MWE. I hope it now makes sense.
    – Karl Hagen
    Commented Apr 20, 2015 at 15:25
5

Here's a solution using the answers package. I use the same mechanism to put the solutions to exercises in the text along with the exercises, but write them to a separate document.

The instructor's manual has correct page references to the students' text, but does not duplicate the contents of that text. The instructor would need both documents to do what your comment suggests you want. I can imagine a way to solve your problem just with the instructor's manual, but don't have the time to work it out.

My instructor's manual looks like this:

enter image description here Workflow: compile book.tex (multiple times if necessary), then instructor.tex.

This compilable MWE has one small bug, commented below in the source, and visible in the output. I must have introduced that cutting down my extensive preamble to isolate the functionality you need. You're welcome to the full preamble if you want it.

The preamble:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% file: preamble.tex
%

% for references across documents - e.g. Instructor manual to main text.
\usepackage{xr}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Notes to the teacher.
% 
%  The commands
%
%  \teachertag
%  \begin{teacher}
%
%  \end{teacher}
%
%  write the contents of the teacher environment to the instructor's
%  manual, tagged with page number and chapter number. The TeX coding
%  requiring \teachertag is a hack I should be able to avoid.
%

\usepackage{answers}

\newcommand{\instructorFileName}{notesfromtext}

% in document, connect instructorfile hook to \instructorFileName
\Newassociation{teacher}{Teacher}{\instructorFileName}


% Kill what the answers package wants to write.
\renewenvironment{Teacher}[4]
{\par}

\newcommand{\teachertag}{%
\Writetofile{\instructorFileName}{
\vspace{0.15in}\hrule\vspace{0.15in}
{\textbf{
Chapter \arabic{chapter},~ page~\arabic{page}
}}
\vspace{0.15in}
}
% optional:
% point to instructor's manual from student version
\footnote{See comment in instructor's manual.}  
}

The frame:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% file: book.tex
%
%%-%%
\documentclass[pdftex,10pt]{book}

\input{preamble}

\Opensolutionfile{\instructorFileName}

\begin{document}

\include{chapter1}
\include{chapter2}

\Closesolutionfile{\instructorFileName}

\end{document}

The chapters:

\chapter{Pythagoras and Euclid}

In this chapter we will show that the Pythagorean Theorem is
equivalent to the Parallel Postulate.
\teachertag{}
\begin{teacher}
xxxxx This is subtle. You will have to go over it slowly.

Note. This comment begins ``xxxxx'' to show that the first few
characters have been gobbled up in the instructor's manual. I fixed
this for my document but it seems to be broken here. I may have time
to fix it here some day. 

and

\chapter{Hyperbolic Geometry}

When there are multiple lines through a point parallel to a given
line, similar triangles are congruent!
\teachertag{}
\begin{teacher}{}
This is subtle too. 
\end{teacher}

The frame for the instructor's manual:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% file: instructor.tex
%
\documentclass[pdftex,10pt]{book}

\input{preamble}

% if you have references to labels in the book
\externaldocument{book}

\begin{document}

This is the instructor's manual.

The pages that follow offer comments on the text,  pedagogical tips
and suggestions for the class.
It's generated from the \TeX{} source so that we can edit it where
it's relevant. When page numbers there change the page references here
change too.

\input{\instructorFileName}

\end{document}
4
  • This answer seems to be on the right track--it's got me thinking anyway. The downside is that it still requires an explicit tag to generate a page reference in the instructor version. Your code, however, got me thinking that perhaps I could use the everyhook package, and in the student edition, check the current page after every vbox. Then, whenever it changed from the last value, write something to the aux file to mark that location. The problem then becomes how to line that up in the instructor edition.
    – Karl Hagen
    Commented Feb 18, 2014 at 13:48
  • 1
    I'm sure there's a way to wrap the teacher environment in an environment that first writes the page numbers to the instructor file, so you won't need the explicit call to my \teachertag. I just never bothered to work it out. Commented Feb 18, 2014 at 15:44
  • Do you have an explanation for the gobbling? Commented Apr 17, 2015 at 3:26
  • @SimonKuang I can't remember, and don't have the time now to read my own code to figure it out. It has something to do with the number of arguments the associated answers package environment accepts. adn's answer above fixes the \teachertag problem. Commented Apr 17, 2015 at 15:00
4

Here is a way that may be helpful:(Edited: marginpar added) suppose your maintext.tex file is like this (after add some marks)

Edit: text with more sense used

       \mtmark{ita}
Here is the revised specification given by k.t.hagen, verbatim: 
1. The answer on SX essentially puts page numbers to the student edition whenever there's an instructor's note.   
                       \mtmark{itaa}
I want one note to mark the start of each student-edition page.
2. The goal is to have one document, used to generate both student and teacher editions,
which means we need to find a way to insert a command,
                       \mtmark{itb}
\begin{equation}
2x+2y=2z
\end{equation}        \mtmark{itbb}
let's call it pagenote, at the appropriate place in the text.
We ought to be able to configure it however we want, 
                      \mtmark{itc}
but what I'm using in Word now translates to something like 
    \mtmark{itcc}
3. We use the option package to control printing of instructor notes. 
(I'm happy to consider other 
\mtmark{ithhh}
%----------------------------
%----------------------------
\opt{\textsf{\lipsum[1-3]}}
%----------------------------
%----------------------------
packages, such as answer, too.) 
                      \mtmark{itd}
However we set it up behind the scenes, 
the user should mark up the notes to the teachers with an 
                      \mtmark{itdd}
command/environment. Those notes only appear in the final output when the document is compiled with the "instructor" option.
                      \mtmark{ite} 
Obviously, the pagination will differ between the two versions. 
                      \mtmark{itee}
\begin{table}
\centering
\begin{tabular}{|c|c|}
\hline 
1 & a \\ 
\hline 
b & 2 \\ 
\hline 
\end{tabular} 
\caption{First table}
\end{table}         
                    \mtmark{itf}
4. My first thought, which I mentioned on TeX.SX, was to work like this: 
First compile the student edition, somehow writing location information 
                      \mtmark{itff}
to an auxiliary file as we go. 
\mtmark{itggg}
%----------------------------
%----------------------------
\opt{\textsf{\lipsum[1-2]}}
%----------------------------
%----------------------------
                      \mtmark{itg} 
Then compile as an instructor's version,
reading that location information and generating the appropriate
commands in the right place. 
                      \mtmark{itgg}
But where I'm stumped is in how to record this positional info. 
It's more than just writing out a page number. We have to encode the place in the text itself. 
                      \mtmark{ith}
5. While writing this email I think I had another idea. Why not have the compilation proceed in three stages: First, do what is, in effect, 
   \mtmark{ithh}
a practice compilation, using the student-version options. 
We use this run to compile an intermediate LaTeX file into which we insert 
 commands at the appropriate point. 
                      \mtmark{iti}
 Those page notes will themselves be controlled by the instructor option. 
 That means we get a "compiled" version of our fragment that would look something like this:
  Some student text goes here. 
                      \mtmark{itii}
 \begin{equation}
2x+2y=2z
\end{equation}        \mtmark{itj}
Blah blah blah  blah blah.  Blah, blah blah The answers package may help here; 
I haven't taken the time to really understand the details of how it works, but it does let you write to external files and read those back in. 
                      \mtmark{itjj}
However we get there, once we have that intermediate file, 
we can simply compile it for student and instructor versions. 
\mtmark{itgh}             
%----------------------------
%----------------------------
\opt{\textsf{\lipsum[1-4]}}
%----------------------------
%----------------------------
  \section{book}                  \mtmark{itk} 
 This is file `book.cls',
 generated with the docstrip utility. 
                     \mtmark{itkk}

 The original source files were:

 classes.dtx  (with options: `book') -
                     \mtmark{itl}

 This is a generated file.-
                      \mtmark{itll}

 Copyright 1993-2014
 The LaTeX3 Project and any individual authors listed elsewhere
 in this file.
                      \mtmark{itm}

%----------------------------
%----------------------------
\opt{\textsf{\lipsum[1-2]}}
%----------------------------
%----------------------------
                    \mtmark{itmm} 
 This file was generated from file(s) of the LaTeX base system.
                      \mtmark{itn}

 It may be distributed and/or modified under the
 conditions of the LaTeX Project Public License, either version 1.3c
 of this license or (at your option) any later version.
                      \mtmark{itnn}
 The latest version of this license is in
    http://www.latex-project.org/lppl.txt
                         \mtmark{ito}
 and version 1.3c or later is part of all distributions of LaTeX
 version 2005/12/01 or later.
                      \mtmark{itoo}

 This file has the LPPL maintenance status "maintained".
                      \mtmark{itp}

 %----------------------------
%----------------------------
\opt{\textsf{\lipsum[1-4]}}
%----------------------------
%----------------------------
                    \mtmark{itpp} 
 This file may only be distributed together with a copy of the LaTeX
 base system. You may however distribute the LaTeX base system without
 such generated files.
                      \mtmark{itq}

 The list of all files belonging to the LaTeX base distribution is
 given in the file `manifest.txt'. 
                      \mtmark{itqq}
 See also `legal.txt' for additional
 information.
                      \mtmark{itr}
 %----------------------------
%----------------------------
\opt{\textsf{\lipsum[1-3]}}
%----------------------------
%----------------------------
                    \mtmark{itrr} 
 The list of derived (unpacked) files belonging to the distribution
 and covered by LPPL is defined by the unpacking scripts (with
 extension .ins) which are part of the distribution.
                      \mtmark{its}

\mtmark{} to be add almost everywhere as possible

and the main file is

Heiko Oberdiek's refcount package used thanks to egreg

\documentclass{article}
\usepackage{lipsum,refcount}

\newcounter{mtt}

\begin{document}

\newcommand{\opt}[1]{}

\newcommand{\mtmark}[1]{%
\label{#1}%
\ifnum\value{mtt}=\getpagerefnumber{#1}\else%
\setcounter{mtt}{\getpagerefnumber{#1}}%
\expandafter\def\csname #1mtlabel\endcsname{}%
\fi}

\input{maintext}


\clearpage
\pagenumbering{arabic}
\renewcommand{\opt}[1]{#1}

\renewcommand{\mtmark}[1]{%
\expandafter\ifx\csname #1mtlabel\endcsname\relax\else%
\marginpar{this is page \pageref{#1}}\fi}

\opt{\input{maintext}}

\end{document}

Now you will get the 2 version in 1 pdf file (you can use titlepage to separte them). What is important is that the instructor's version have approximative indications in the sense you ask for.

the inconvenience is you should be careful to repeated labels (marks).

9
  • 1
    downvoted without any comment?
    – touhami
    Commented Apr 17, 2015 at 15:58
  • 3
    I also dont like downvoting an answer without any comment explaining the reason for it. Commented Apr 18, 2015 at 16:08
  • I don't see any marginpar page numbers when I try compiling your solution. Also, note that the equations number consecutively, so the equation numbering in the instructor's edition starts at 3.
    – Karl Hagen
    Commented Apr 20, 2015 at 20:32
  • Also, placing mtmark commands throughout the document doesn't strike me as very usable.
    – Karl Hagen
    Commented Apr 20, 2015 at 20:33
  • @k.t.hagen you are right but any thing else is very hard if not impossible.
    – touhami
    Commented Apr 20, 2015 at 20:58
1

I think I have come pretty close to a real solution. It's not particularly minimal, but it does most of what I hoped to accomplish. Basically this works by redefining line breaks in the source code to hook a counter that increments line by line except inside instructornotes.

For the initial student compile, we hook into every shipout to record the line number of the last line of the shipped page as well as the page number of the post-ship page. This composes an auxiliary file full of conditional commands that check whether a student page number should be printed at this line of source code in the teacher edition.

For the teacher compile, we \input that auxiliary file at every line of the source code.

First compile with \teacheredfalse to get the student edition and build the page number database, copy or rename the student PDF document, then compile with \teacheredtrue to get the teacher edition.

\documentclass[14pt]{memoir}
\usepackage[spacing, tracking]{microtype}
\usepackage{libertine}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{xspace}
\usepackage{ifthen}
\usepackage{everyshi}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage{newverbs}
\Verbdef\verbpercent{%}

% compile once with \teacheredfalse, copy out the student PDF, then compile once with \teacheredtrue
\newif\ifteachered
\teacheredfalse
\teacheredtrue

\newif\ifinsnote
\insnotefalse
\newcommand{\instructornote}[1]{%
    \insnotetrue%
    \ifteachered%
        {\noindent%
            \sffamily\bfseries\selectfont%
            #1}%
    \fi%
    \ignorespaces%
    \insnotefalse%
}

\linespread{1.5}
% to get good non-French spacing with microtype spacing option
\nonfrenchspacing
\microtypecontext{spacing=nonfrench}

\ifteachered\else
% make an output stream for recording line numbers
\newwrite\linenofile
% set job.lineno as output file
\immediate\openout\linenofile=\jobname.lineno
\fi

% records
\newcommand{\linestomark}{}
\newcounter{linebeforesrc}
\newcounter{nextpage}
\makeatletter
\newcommand{\display@pagemark}[1]{%
    \begin{marginfigure}%
        \normalfont---Page~#1---%
    \end{marginfigure}%
    }
\def\fmtlinewrite#1#2{\string\ifthenelse\string{\string\equal\string{\string\thesrcline\string}\string{#1\string}\string}\string{\string\display@pagemark\string{#2\string}%
        \string}\string{\string}}
\makeatother
\def\linewrite{%
    \setcounter{linebeforesrc}{\thesrcline}
    \addtocounter{linebeforesrc}{-1}
    \setcounter{nextpage}{\thepage}
    \addtocounter{nextpage}{1}
    \immediate\write\linenofile{\fmtlinewrite{\thelinebeforesrc}{\thenextpage}\verbpercent}
}

% % % line numbering definition
\newcounter{srcline}
% marks line number --- this is temporary
\makeatletter
\newcommand{\line@mark}{\textcolor{red}{\textsc{Line~\thesrcline}}}
\newcommand{\linemark}{%
    \ifinsnote\else%
    \stepcounter{srcline}%
    \makeatletter%
    \ifteachered%
    \input{\jobname.lineno}%
    \fi%
    \makeatother%
    \fi%
    }
\makeatother

% Playing with the gobbling of \par
\makeatletter
% new par definition inside srclines, includes line mark
{\obeylines\gdef\srclinepar{%
        \@ifnextchar{^^M}{\endgraf\linemark\expandafter\srclinepar\@gobble}{\linemark\xspace}}}
\makeatother

\newenvironment{tracklines}
{\endgraf\let\par\srclinepar\obeylines}
{\endgraf}
% % % end

\ifteachered\else
\EveryShipout{\linewrite}
\fi
\begin{document}
    \begin{tracklines}
        Lorem ipsum dolor sit amet, mel novum mazim integre id,
        feugiat assueverit cu vel? Eu mea solet equidem, dolor
        democritum qui in, in vis unum ullum! Magna labores omittam
        at qui, cu wisi tation eam! Usu ea tota simul aliquam,
        postea latine diceret cu sit?

        Natum nobis vituperatoribus has at. Id autem consequat his,
        alterum dolorem eu pri. Vocent temporibus reformidans eum
        ei? Sed sumo justo iriure eu. Agam liber aliquando nec eu,
        nullam omnesque mel te, bonorum accumsan repudiare eu vis.

        Usu eu nonumy scribentur voluptatibus, illud impedit
        ponderum qui ne. Per at nulla noster alterum! Qui ea mutat
        brute abhorreant, an intellegam persequeris nec. Modus
        utinam maiestatis mel ex? Quo an sint volumus denique, an
        duo homero platonem mnesarchum?

        In nihil recteque vix. Te prima facilisis mea, te pri ipsum
        harum dissentias. Ne rebum tation invenire usu. Mel ne paulo
        detraxit, vix possit pericula definitionem te, no purto
        graeco nostro mei.

        Usu eu nonumy scribentur voluptatibus, illud impedit
        ponderum qui ne. Per at nulla noster alterum! Qui ea mutat
        brute abhorreant, an intellegam persequeris nec. Modus
        utinam maiestatis mel ex? Quo an sint volumus denique, an
        duo homero platonem mnesarchum?

        In nihil recteque vix. Te prima facilisis mea, te pri ipsum
        harum dissentias. Ne rebum tation invenire usu. Mel ne paulo
        detraxit, vix possit pericula definitionem te, no purto
        graeco nostro mei.

        \instructornote{Natum nobis vituperatoribus has at. Id autem consequat his,
            alterum dolorem eu pri. Vocent temporibus reformidans eum
            ei? Sed sumo justo iriure eu. Agam liber aliquando nec eu,
            nullam omnesque mel te, bonorum accumsan repudiare eu vis.

            Usu eu nonumy scribentur voluptatibus, illud impedit
            ponderum qui ne. Per at nulla noster alterum! Qui ea mutat
            brute abhorreant, an intellegam persequeris nec. Modus
            utinam maiestatis mel ex? Quo an sint volumus denique, an
            duo homero platonem mnesarchum?}

        Ei aperiri interesset eum, vix cu nominati expetenda
        efficiantur, nonumes forensibus no mel! Eum ad natum ferri
        efficiantur, causae tincidunt vix in? Ad nullam recusabo
        consulatu mei, vel at alii definitionem vituperatoribus? His
        ne oblique expetenda, sit ex nemore consulatu. Cum ut
        malorum facilisi?

        Salutatus honestatis reprehendunt ius in. Te mea tempor
        iriure. Munere labore pericula in vel, at nam dicam civibus,
        quas movet sit ut. Albucius petentium dissentias eum cu! Vim
        mucius phaedrum te, eum te eligendi sadipscing.

        Vis tollit invenire tractatos eu, admodum legendos
        deterruisset usu at, ornatus vivendo maiestatis ex vel. No
        tamquam erroribus nec, te per idque suscipit phaedrum.
        Noster aliquando et cum, quo partem oblique ut, has ei vidit
        reque delicatissimi! Et brute definiebas repudiandae pro, ea
        quo iusto graecis necessitatibus!

        Ius velit erant eu. His an enim audiam complectitur. Nibh
        legendos atomorum vix ex. Has eu quaeque copiosae, nam no
        delicata corrumpit?

        Vim eu fugit hendrerit dissentias, vis laudem postulant et,
        et nam moderatius complectitur. Mea ex animal tibique
        salutatus? Duo ea postulant definitionem? Vis omnes
        deterruisset no, pri nihil impetus propriae ex? Ei vis brute
        molestie percipitur.

        Eum ea oblique conceptam, quo ridens audire referrentur an.
        Sea cu veri fastidii apeirian, per possit latine referrentur
        an! In ubique patrioque duo, facilis omittam efficiantur usu
        ex, an per aperiri efficiantur! Qui etiam aliquid posidonium
        an.

        Cu sit ludus dolorem probatus! An nibh minim utamur his. Pro
        nibh liber in, ei principes definitiones qui. Et est malis
        tantas recusabo.

        Diam periculis conclusionemque id cum. Hendrerit argumentum
        nam ut. Wisi atomorum expetendis his ea, vim velit nullam
        sapientem ei, in his novum sonet commune! Sonet oportere his
        ut, ut putent saperet disputationi mel. No sit sale ornatus
        democritum, duo latine senserit ad, sonet voluptua recusabo
        vis ne.

        Mea et agam maluisset, per id vitae meliore. At tota
        convenire repudiandae vel! Dico patrioque definitiones ad
        qui? Tamquam adolescens vituperatoribus pro ea, eu verear
        eligendi sed? Mediocrem gubergren ut has, ea ius illud
        legere fuisset.

        \instructornote{Salutatus honestatis reprehendunt ius in. Te mea tempor
            iriure. Munere labore pericula in vel, at nam dicam civibus,
            quas movet sit ut. Albucius petentium dissentias eum cu! Vim
            mucius phaedrum te, eum te eligendi sadipscing.

            Vis tollit invenire tractatos eu, admodum legendos
            deterruisset usu at, ornatus vivendo maiestatis ex vel. No
            tamquam erroribus nec, te per idque suscipit phaedrum.
            Noster aliquando et cum, quo partem oblique ut, has ei vidit
            reque delicatissimi! Et brute definiebas repudiandae pro, ea
            quo iusto graecis necessitatibus!

            Ius velit erant eu. His an enim audiam complectitur. Nibh
            legendos atomorum vix ex. Has eu quaeque copiosae, nam no
            delicata corrumpit?

            Vim eu fugit hendrerit dissentias, vis laudem postulant et,
            et nam moderatius complectitur. Mea ex animal tibique
            salutatus? Duo ea postulant definitionem? Vis omnes
            deterruisset no, pri nihil impetus propriae ex? Ei vis brute
            molestie percipitur.

            Eum ea oblique conceptam, quo ridens audire referrentur an.
            Sea cu veri fastidii apeirian, per possit latine referrentur
            an! In ubique patrioque duo, facilis omittam efficiantur usu
            ex, an per aperiri efficiantur! Qui etiam aliquid posidonium
            an.}

        No nam legendos neglegentur. Ex appetere intellegam cum,
        posse lucilius vim eu. Has eu eleifend instructior, sit in
        facer ancillae. Veniam graece usu ne, in vel accusam
        salutandi efficiantur. Te qui latine facilis maiestatis,
        ludus iudico vivendo an nam. Delectus repudiare et his.

        Sed at meis doctus! Ea sit omnes percipit petentium, vix ei
        aliquid detraxit petentium, quo ne melius delectus
        concludaturque? Eum in aliquip aliquam, sapientem evertitur
        et vim, ut vix dictas sanctus! Ut graeco legendos platonem
        quo? Id cum cibo iudico interesset, dico disputando mel ut!
        Suas delicata forensibus pri eu, pri ad saperet constituam.

        Novum mnesarchum id pri, case cibo at vim? Liber soleat sea
        ei. At duis minim nullam has, illum apeirian id his,
        ponderum explicari id vix! Ne duo affert detracto
        honestatis!

        An ubique dicunt aliquid est, quo id tota mutat aliquid?
        Decore verterem cum et? Zril melius his ad, affert mucius
        sea ea! Ut idque impetus cum.

        Ad sed illud tation tractatos, eu mea soleat verear. No usu
        iudico decore altera. Eos no alienum deleniti persequeris,
        nam aeterno aliquando inciderint ea! Sensibus iracundia mel
        no. Eu utroque expetenda scribentur sit, te vim quot melius
        qualisque?

        Invenire erroribus ea cum, ne qui augue assentior, etiam
        altera definitiones id mei! At eius aperiam numquam quo, et
        nam option vivendo scribentur? Per tale porro interpretaris
        et, his in vide dicunt? Ut latine eripuit efficiendi mel?

        Ea homero fabellas eos, vim solet iudico graeci ex. Sit no
        esse omittam detracto! Nam eu novum percipit, ne sea diam
        quando, dicant prompta cu pro. Ea his nominati sensibus
        consequat. Est labore euismod reprehendunt cu?
    \end{tracklines}
\end{document}

Limitations of my approach:

  1. So far, the line tracking does not seem to work when I enclose instructor notes in an environment such as oframed from framed.
  2. The input source file has to have a reasonable (viz. large) number of periodic line breaks (e.g. \n) in its paragraphs.
  3. The page number printing in the teacher edition is usually a couple lines early (in the teacher edition).
  4. The final page number is printed way too late.
3
  • Big thanks to answerers of my recent questions (1, 2, 3). Commented Jun 24, 2015 at 23:49
  • Also, if you're feeling bored, you can switch this over to etoolbox's toggle toolset. Commented Jun 24, 2015 at 23:55
  • tracklines can be hooked over document using etoolbox. Commented Aug 5, 2015 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .