diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/repltext/repltext.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/repltext/repltext.dtx | 84 |
1 files changed, 67 insertions, 17 deletions
diff --git a/Master/texmf-dist/source/latex/repltext/repltext.dtx b/Master/texmf-dist/source/latex/repltext/repltext.dtx index b75a3c1b8fe..9a116df516a 100644 --- a/Master/texmf-dist/source/latex/repltext/repltext.dtx +++ b/Master/texmf-dist/source/latex/repltext/repltext.dtx @@ -1,7 +1,7 @@ % \iffalse meta-comment % -% Copyright (C) 2014 by Scott Pakin <scott+repl@pakin.org> -% --------------------------------------------------------- +% Copyright (C) 2014-2020 Scott Pakin <scott+repl@pakin.org> +% ---------------------------------------------------------- % % This file may be distributed and/or modified under the conditions of % the LaTeX Project Public License, either version 1.3c of this license @@ -22,11 +22,12 @@ %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{repltext} %<*package> - [2014/04/11 v1.0 PDF replacement text] + [2020/09/25 v1.1 PDF replacement text] %</package> % %<*driver> \documentclass{ltxdoc} +\usepackage[T1]{fontenc} \usepackage{repltext} \usepackage{graphicx} \usepackage{color} @@ -46,13 +47,13 @@ pdfauthor={Scott Pakin}, pdfsubject={LaTeX package for PDF replacement text}, pdfkeywords={LaTeX, PDF, replacement text, ActualText, copy and paste}, - pdfcopyright={Copyright (C) 2014, Scott Pakin}, + pdfcopyright={Copyright (C) 2014-2020 Scott Pakin}, pdflicenseurl={http://www.latex-project.org/lppl/}, pdfcaptionwriter={Scott Pakin}, pdfcontactemail={scott+repl@pakin.org}, pdfcontacturl={http://www.pakin.org/\xmptilde scott/}, pdflang={en-US}, - baseurl={http://www.ctan.org/tex-archive/macros/latex/contrib/repltext/repltext.pdf}, + baseurl={http://mirror.ctan.org/macros/latex/contrib/repltext/repltext.pdf}, % colorlinks=false, pdfstartview=Fit @@ -60,13 +61,13 @@ \begin{document} \DocInput{repltext.dtx} -% \PrintChanges + \PrintChanges \PrintIndex \end{document} %</driver> % \fi % -% \CheckSum{38} +% \CheckSum{59} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -86,11 +87,12 @@ % % % \changes{v1.0}{2014/04/11}{Initial version} +% \changes{v1.1}{2020/09/25}{Support modern Lua\protect\LaTeX\ versions} % % \GetFileInfo{repltext.dtx} % -% \DoNotIndex{\bgroup,\catcode,\egroup,\expandafter,\global,\let} -% \DoNotIndex{\newcommand,\newenvironment,\the} +% \DoNotIndex{\{,\},\bgroup,\catcode,\def,\egroup,\expandafter,\global,\let} +% \DoNotIndex{\newcommand,\newenvironment,\protected,\providecommand,\the} % % ^^A Define some logical styles. % \newcommand{\pkgname}[1]{^^A @@ -322,13 +324,58 @@ % % \section{Implementation} % -% \pkgname{repltext} relies on the \cs{pdfliteral} and -% \cs{pdfescapestring} primitives, which are defined only by -% pdf\LaTeX\ and Lua\LaTeX\@. We use the \pkgname{ifpdf} package to -% test for one of those two \tex\ engines. +% This section presents the documented source code for +% \pkgname{repltext}. Most users can ignore this section. % +% \begin{macro}{\@ifdefined} +% I find \cs{@ifdefined} a more natural construct than \cs{@ifundefined}. % \begin{macrocode} -\RequirePackage{ifpdf} +\providecommand{\@ifdefined}[3]{\@ifundefined{#1}{#3}{#2}} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\repl@literal} +% \pkgname{repltext} needs a mechanism to insert literal PDF code. This +% varies by \TeX\ engine so we have to define \cs{repl@literal} on an +% engine-by-engine basis. +% \changes{v1.1}{2020/09/25}{Add this macro} +% \begin{macrocode} +\@ifdefined{pdfliteral}{% +% \end{macrocode} +% \latex[pdf] +% \begin{macrocode} + \let\repl@literal=\pdfliteral +}{% + \@ifdefined{pdfextension}{% +% \end{macrocode} +% \latex[Lua] +% \begin{macrocode} + \protected\def\repl@literal{\pdfextension literal}% + }{% +% \end{macrocode} +% Other +% \begin{macrocode} + \PackageError{repltext}{Unrecognized TeX engine}{% + The repltext package currently works only with pdfLaTeX and\MessageBreak + LuaLaTeX.\space\space Please use of those engines to build your document.% + }% + }% +}% +% \end{macrocode} +% \end{macro} +% +% \pkgname{repltext} additionally needs a mechanism to escape +% backslashes and parentheses in a string to make it usable as a PDF +% string. This is easy in pdf\LaTeX, which provides +% \cs{pdfescapestring}. Unfortunately, to my knowledge, no other +% \TeX\ engine provides equivalent functionality. Rather than write our +% own function, we leverage \pkgname{hyperref}'s \cs{Hy@pstringdef}, +% which provides similar functionality. +% \begin{macrocode} +\RequirePackage{etoolbox} +\AtEndPreamble{% + \@ifpackageloaded{hyperref}{}{\RequirePackage{hyperref}}% +} % \end{macrocode} % % The \cs{repl@text@ii} macro invokes \cs{scalebox}, which is defined by @@ -381,6 +428,7 @@ % \end{macro} % % \begin{macro}{\repl@text@ii} +% \begin{macro}{\repl@escaped} % \cs{repl@text@ii} is the macro that finally outputs something. It % takes ordinary \LaTeX\ code as its argument and writes a PDF % marked-content sequence that uses an \pdfname{ActualText} entry to @@ -389,8 +437,9 @@ % second argument (\cs{repl@text@ii}'s |#1|~argument). % \begin{macrocode} \newcommand{\repl@text@ii}[1]{% - \pdfliteral{ - /Span << /ActualText (\pdfescapestring{\the\repl@text@toks}) >> + \Hy@pstringdef\repl@escaped{\the\repl@text@toks}% + \repl@literal{ + /Span << /ActualText (\repl@escaped) >> BDC }% #1% @@ -402,10 +451,11 @@ % without being noticeable. % \begin{macrocode} \scalebox{0.000001}{-}% - \pdfliteral{EMC}% + \repl@literal{EMC}% } % \end{macrocode} % \end{macro} +% \end{macro} % % \begin{macro}{\prevrepl} % For the author's convenience we define \cs{prevrepl} to refer to the |