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:
- So far, the line tracking does not seem to work when I enclose instructor notes in an environment such as
oframed
from framed
.
- The input source file has to have a reasonable (viz. large) number of periodic line breaks (e.g.
\n
) in its paragraphs.
- The page number printing in the teacher edition is usually a couple lines early (in the teacher edition).
- The final page number is printed way too late.
\documentclass{...}
and ending with\end{document}
.