% File: pdfcolmk.sty % Version: 2005/07/09 v0.7 % Author: Heiko Oberdiek % Email: % % Copyright: Copyright (C) 2000, 2005 Heiko Oberdiek. % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either % version 1.3 of this license or (at your option) any later % version. The latest version of this license is in % http://www.latex-project.org/lppl.txt % and version 1.3 or later is part of all distributions of % LaTeX version 2003/12/01 or later. % % This work has the LPPL maintenance status "maintained". % % This Current Maintainer of this work is Heiko Oberdiek. % % Function: This package tries a solution for the missing color % stack of pdfTeX. % % Background: After the Dante meeting (Clausthal 2000) I have started % to experiment with the eTeX method of a `colour' mark. % One of the major problems is the understanding of the % output routine and the need to rewrite it because of % missing hooks. Currently I have made some tests in % in onecolumn and twocolumn mode, but the state is % experimental. % % Limitations: * mark limitations: page breaks in math % * LaTeX's output routine is redefinded. % * Changes in the output routine of newer versions % of LaTeX are not detected. % * Packages that change the output routine are not % supported. % * It does not support several independent text % streams like footnotes. % % Recommended: e-TeX (for additional mark register) % Without e-TeX LaTeX's mark commands are redefined % to store an additional color value. % % Use: Load after package color: % \usepackage[pdftex]{color} % \usepackage{pdfcolmk} % % Compatibility: % * Load the following packages after `pdfcolmk': % mparhack.sty % * Load the following packages before `pdfcolmk': % marn.sty % newmarn.sty % * Supported \@addmarginpar patch: % latex/base/latex.ltx % memoir.cls % poemscol/marn.sty, poemscol/newmarn.sty % mparhack.sty % * Unsupported \@addmarginpar patch: % lineno.sty % sttools/marginal.sty % revtex4.cls % % History: 2000/08/27 v0.1: % first published version % (comp.text.tex, pdftex@tug.org) % 2000/09/02 v0.2: % * next try. % 2000/09/02 v0.3: % * solution without e-TeX added. % 2000/09/06 v0.4: % * Patch commands added. % * Patch for seminar.cls added. % 2000/09/06 v0.5: % * Bug fix: initialization of \pec@value added. % 2005/06/15 v0.6: % * Support for \marginpar added. % See thread in comp.text.tex % (Message-ID: d86d3r$kpv$1@news.BelWue.DE). % 2005/07/09 v0.7: % * Output support added for memoir, % provided by Lars Madsen. % \NeedsTeXFormat{LaTeX2e}[1997/11/09] \ProvidesPackage{pdfcolmk}[2005/07/09 v0.7 PDFtex COLor MarK (HO)] \@ifundefined{ver@pdftex.def}{% \PackageWarningNoLine{pdfcolmk}{% Nothing to fix, because \string`pdftex.def\string' not loaded% }% \endinput }{} \@ifpackageloaded{color}{}{% \PackageWarningNoLine{pdfcolmk}{% Nothing to fix, because \string`color.sty\string' not loaded% }% \endinput } \PackageInfo{pdfcolmk}{% This package tries to simulate dvips's color stack\MessageBreak for pdfTeX based on a mark register of e-TeX.\MessageBreak It redefines LaTeX's output routine. Therefore\MessageBreak use with care, no warranties% } \ifx\marks\@undefined \let\pec@mark\mark \let\pec@value\empty \long\def\mark#1{% \protected@xdef\pec@value{#1}% \pec@setmark } \def\pec@setmark{% \begingroup \@temptokena\expandafter{\pec@value}% \pec@mark{{\current@color}\the\@temptokena}% \endgroup } \def\pec@getmark{% \xdef\pec@botcolor{% \expandafter\@firstofthree\botmark\@empty\@empty\@empty }% } \long\def\@firstofthree#1#2#3{#1}% \CheckCommand{\@leftmark}[2]{#1} \CheckCommand{\@rightmark}[2]{#2} \CheckCommand*{\leftmark}{% \expandafter\@leftmark\botmark\@empty\@empty } \CheckCommand*{\rightmark}{% \expandafter\@rightmark\firstmark\@empty\@empty } \long\def\@leftmark#1#2#3{#2} \long\def\@rightmark#1#2#3{#3} \g@addto@macro\leftmark\@empty \g@addto@macro\rightmark\@empty \else \RequirePackage{etex}[1998/03/26] \newmarks\pec@marks \def\pec@setmark{\marks\pec@marks{\current@color}} \def\pec@getmark{\xdef\pec@botcolor{\botmarks\pec@marks}} \fi % \marginpar fix \chardef\pec@result\z@ \def\pec@temp#1{% \chardef\pec@result\@ne \begingroup \let\on@line\@empty \PackageInfo{pdfcolmk}{% Patch for \string\@addmarginpar\space applied (#1)% }% \endgroup } % Variant: latex/base/latex.ltx \def\pec@addmarginpar{% \@next\@marbox\@currlist{% \@cons\@freelist\@marbox \@cons\@freelist\@currbox }\@latexbug \@tempcnta\@ne \if@twocolumn \if@firstcolumn \@tempcnta\m@ne \fi \else \if@mparswitch \ifodd\c@page \else \@tempcnta\m@ne \fi \fi \if@reversemargin \@tempcnta -\@tempcnta \fi \fi \ifnum\@tempcnta <\z@ \global\setbox\@marbox\box\@currbox \fi \@tempdima\@mparbottom \advance\@tempdima -\@pageht \advance\@tempdima\ht\@marbox \ifdim\@tempdima >\z@ \@latex@warning@no@line{Marginpar on page \thepage\space moved}% \else \@tempdima\z@ \fi \global\@mparbottom\@pageht \global\advance\@mparbottom\@tempdima \global\advance\@mparbottom\dp\@marbox \global\advance\@mparbottom\marginparpush \advance\@tempdima -\ht\@marbox \global\setbox\@marbox\vbox{% \vskip \@tempdima \box \@marbox }% \global \ht\@marbox \z@ \global \dp\@marbox \z@ \kern -\@pagedp \nointerlineskip \hb@xt@\columnwidth{% \ifnum \@tempcnta >\z@ \hskip\columnwidth \hskip\marginparsep \else \hskip -\marginparsep \hskip -\marginparwidth \fi \box\@marbox \hss }% \nointerlineskip \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}% } \ifx\pec@addmarginpar\@addmarginpar \pec@temp{latex/base}% \fi % Variant: memoir.cls \def\pec@addmarginpar{% \checkoddpage \@next\@marbox\@currlist{% \@cons\@freelist\@marbox \@cons\@freelist\@currbox }\@latexbug \@tempcnta\@ne \if@twocolumn \if@firstcolumn \@tempcnta\m@ne \fi \else \if@mparswitch \ifoddpage \else \@tempcnta\m@ne \fi \fi \if@reversemargin \@tempcnta -\@tempcnta \fi \fi \ifnum\@tempcnta <\z@ \global\setbox\@marbox\box\@currbox \fi \@tempdima\@mparbottom \advance\@tempdima -\@pageht \advance\@tempdima\ht\@marbox \ifdim\@tempdima >\z@ \@latex@warning@no@line{% Marginpar on page \thepage\space moved by \the\@tempdima }% \else \@tempdima\z@ \fi \global\@mparbottom\@pageht \global\advance\@mparbottom\@tempdima \global\advance\@mparbottom\dp\@marbox \global\advance\@mparbottom\marginparpush \advance\@tempdima -\ht\@marbox \global\setbox\@marbox\vbox{% \vskip \@tempdima \box \@marbox }% \global \ht\@marbox \z@ \global \dp\@marbox \z@ \kern -\@pagedp \nointerlineskip \hb@xt@\columnwidth{% \ifnum \@tempcnta >\z@ \hskip\columnwidth \hskip\marginparsep \else \hskip -\marginparsep \hskip -\marginparwidth \fi \box\@marbox \hss }% \nointerlineskip \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}% }% \ifx\pec@addmarginpar\@addmarginpar \pec@temp{memoir.cls}% \fi % Variant: poemscol/marn.sty, poemscol/newmarn.sty \def\pec@addmarginpar{% \@next \@marbox\@currlist{% \@cons\@freelist\@marbox \@cons\@freelist\@currbox }\@latexbug \global\advance\@mpar@count\m@ne \@ifundefined{@marn@\the\@mpar@count @}{% was location logged last time? \@tempcnta\@ne % NO: use original LaTeX logic \if@twocolumn \if@firstcolumn \@tempcnta\m@ne \fi \else \if@mparswitch \ifodd\c@page \else \@tempcnta\m@ne \fi \fi \if@reversemargin \@tempcnta -\@tempcnta \fi \fi }{% \@tempcnta % YES: use record from last time to decide side. \@nameuse{@marn@\the\@mpar@count @}% \if@reversemargin -\fi \@ne }% \ifnum\@tempcnta <\z@ \global\setbox\@marbox\box\@currbox \global\let\@marnbottom\@mparbottoml \else \global\let\@marnbottom\@mparbottom \fi \@tempdima\@marnbottom \advance\@tempdima -\@pageht \advance\@tempdima\ht\@marbox \ifdim\@tempdima >\z@ \@@warning{Marginpar on page \thepage\space moved}% \else \@tempdima\z@ \fi \global\@marnbottom\@pageht \global\advance\@marnbottom\@tempdima \global\advance\@marnbottom\dp\@marbox \global\advance\@marnbottom\marginparpush \advance\@tempdima -\ht\@marbox \global\ht\@marbox\z@ \global\dp\@marbox\z@ \vskip -\@pagedp \vskip\@tempdima\nointerlineskip \hbox to\columnwidth{% \ifnum \@tempcnta >\z@ \hskip\columnwidth \hskip\marginparsep \else \hskip -\marginparsep \hskip -\marginparwidth \fi \if@filesw % record where this is for use next time: \@marn@log\@mpar@count \fi \box\@marbox \hss }% \nobreak %% RmS 91/06/21 \nobreak added \vskip -\@tempdima \nointerlineskip \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}% } \ifx\pec@addmarginpar\@addmarginpar \pec@temp{poemscol/(new)marn.sty}% \fi % Variant: refman/refart.cls, refnam/refrep.cls \def\pec@addmarginpar{% \@next\@marbox\@currlist{% \@cons\@freelist\@marbox \@cons\@freelist\@currbox }\@latexbug \@tempcnta\@ne \if@twocolumn \if@firstcolumn \@tempcnta\m@ne \fi \else \@tempcnta\m@ne \fi \ifnum\@tempcnta <\z@ \global\setbox\@marbox\box\@currbox \fi \@tempdima\@mparbottom \advance\@tempdima -\@pageht \advance\@tempdima\ht\@marbox \ifdim\@tempdima >\z@ \@@warning{Marginpar on page \thepage\space moved}% \else \@tempdima\z@ \fi \global\@mparbottom\@pageht \global\advance\@mparbottom\@tempdima \global\advance\@mparbottom\dp\@marbox \global\advance\@mparbottom\marginparpush \advance\@tempdima -\ht\@marbox \global\setbox\@marbox\vbox{% \vskip \@tempdima \box \@marbox }% \global \ht\@marbox \z@ \global \dp\@marbox \z@ \kern -\@pagedp \nointerlineskip \hb@xt@\columnwidth{% \ifnum \@tempcnta >\z@ \hskip\columnwidth \hskip\marginparsep \else \hskip -\marginparsep \hskip -\marginparwidth \fi \box\@marbox \hss }% \nointerlineskip \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}% } \ifx\pec@addmarginpar\@addmarginpar \pec@temp{ref(art|rep).cls}% \fi \ifcase\pec@result \PackageInfo{pdfcolmk}{% Fix for \string\@addmarginpar\space is omitted, % because this variant\MessageBreak of \string\@addmarginpar\space is not recognized% }% \else % apply patch for \@addmarginpar \def\pec@PatchAddMarginpar#1\columnwidth#2#3\@nil{% \pec@PatchAddMarginparI#2\@nil{#1}{#3}% }% \def\pec@PatchAddMarginparI#1\box\@marbox\hss#2\@nil#3#4{% \def\@addmarginpar{% #3% \columnwidth{% #1% \pdfliteral{q}% \rlap{% \box\@marbox }% \pdfliteral{Q}% \hss #2% }% #4% }% }% \expandafter\pec@PatchAddMarginpar\@addmarginpar\@nil \fi % color fix \def\set@color{% \pdfliteral{\current@color}% \ifinner \else \pec@setmark \fi \aftergroup\reset@color } \def\reset@color{% \pdfliteral{\current@color}% \ifinner \else \pec@setmark \fi } \let\pec@botcolor\current@color \def\pec@PatchVBoxCCLV{% \ifx\pec@botcolor\@empty \else \setbox\@cclv\vbox{% \pdfliteral{\pec@botcolor}% \unvbox\@cclv }% \fi \pec@getmark } \def\pec@PatchAlreadyInBox{% \ifx\pec@botcolor\@empty \else \pdfliteral{\pec@botcolor}% \fi \pec@getmark } \@ifclassloaded{memoir}{% \expandafter\def\expandafter\mem@makecol\expandafter{% \expandafter\pec@PatchVBoxCCLV \mem@makecol }% \endinput }{} \@ifclassloaded{seminar}{% \newcommand\pec@org@makeslide{} \let\pec@org@makeslide\@makeslide \def\@makeslide{% \pec@PatchVBoxCCLV \pec@org@makeslide }% \endinput }{} \long\def\pec@output#1\@specialoutput\else#2\pec@end{% \begingroup \def\x{#2}% \expandafter\endgroup \ifx\x\@empty \PackageWarningNoLine{pdfcolmk}{% Unexpected \string\output\space routine detected,% \MessageBreak loading of package stopped% }% \expandafter\endinput \fi } \expandafter\expandafter\expandafter\pec@output \expandafter\@firstofone\the\output\@specialoutput\else\pec@end \long\def\pec@output#1\@specialoutput\else#2\pec@end{% \output{% #1\@specialoutput\else \pec@PatchVBoxCCLV #2% }% } \expandafter\expandafter\expandafter\pec@output \expandafter\@firstofone\the\output\pec@end \endinput