summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/aeb_mobile/aeb_mobile.dtx
blob: 8741a1ac4ca506899c5b5c49ea033fad44e70e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
%\iffalse
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% aeb_mobile.sty package                               %%
%% Copyright (C) 2012-2018                              %%
%%   dpstory@acrotex.net                                %%
%%                                                      %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License        %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
%<package>\ProvidesPackage{aeb_mobile}
%<package> [2018/04/26 v1.4 aeb\_mobile: Formatting for mobile devices (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,hyperindex=false]{hyperref}
%\pdfstringdefDisableCommands{\let\\\textbackslash}
%\EnableCrossrefs \CodelineIndex
\OnlyDescription  % comment out for implementation details
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\InputIfFileExists{aebdocfmt.def}{\PackageInfo{web}{Inputting aebdocfmt.def}}
    {\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
     \PackageInfo{web}{aebdocfmt.def cannot be found}}
\begin{document}
\def\CMD#1{\textbackslash#1}
\let\pkg\textsf
\let\opt\texttt
\addtolength{\marginparwidth}{3pt}
  \GetFileInfo{aeb_mobile.sty}
  \title{\texorpdfstring{\protect\pkg{aeb\_mobile}}{aeb_mobile}: Formatting for mobile devices}
  \author{D. P. Story\\
    Email: \texttt{dpstory@acrotex.net}}
  \date{processed \today}
  \maketitle
  \tableofcontents
  \DocInput{aeb_mobile.dtx}
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here.\\Execute
    \texttt{makeindex -s gind.ist -o aeb\_mobile.ind aeb\_mobile.idx} on the command line and recompile
    \texttt{aeb\_mobile.dtx}.}
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here.\\Execute
    \texttt{makeindex -s gglo.ist -o aeb\_mobile.gls aeb\_mobile.glo} on the command line and recompile
    \texttt{aeb\_mobile.dtx}.}
\end{document}
%</driver>
% \fi
% \MakeShortVerb{|}
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}}
%    {\PackageInfo{web}{cannot find aebdonotindex.def}}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% If \cs{ifsmartphone} is undefined, we do nothing; otherwise, if \texttt{true}
% we load the package, if \texttt{false} we end the package. With this, we don't
% need to surround the \textsf{aeb\_mobile} package with \cs{ifsmartphone}\dots\cs{fi}.
%\changes{v1.1}{2012/06/26}{Added a check for \cs{ifsmartphone}}
%    \begin{macrocode}
\@ifundefined{ifsmartphone}{\newif\ifsmartphone\smartphonetrue}{}
%    \end{macrocode}
% \section{Introduction}
%This is a simple package designed to format a document for a smart phone.
%When the option \texttt{smartphone} is taken a page $4\times8$ inches is
%created. Other definitions are made, as explained below.
%
%    \begin{macrocode}
%</package>
%<*altpkgname>
%    \end{macrocode}
%
% \section{Alternate package name: \texorpdfstring{\protect\pkg{aeb-mobile}}{aeb-mobile}}
% CTAN lists this package (\pkg{aeb\_mobile}) as \pkg{aeb-mobile}, so we'll create
% a dummy package by that name.
% \changes{v1.3}{2018/04/26}{Added dummy package \string\pkg{aeb-mobile}}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{aeb-mobile}
 [2018/04/26 v1.0 aeb-mobile Alt-name (dps)]
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{aeb_mobile}}
\ProcessOptions
\RequirePackage{aeb_mobile}
%    \end{macrocode}
%    \begin{macrocode}
%</altpkgname>
%<*package>
%    \end{macrocode}
% \section{The code}
% In this main body of the package, we set page dimensions, the inital
% view of the PDF, define a title page, define links and the JavaScript
% they use.
% \subsection{Set Package Options}
%    \begin{macro}{smartphone}
% First, we get the options.For the \texttt{smartphone}
% option we have an  $4\times8$ inch page, with narrow side margins.
%    \begin{macrocode}
\DeclareOption{smartphone}{\ifsmartphone\AtEndOfPackage{%
    \web@MargScrDimOpts{.25in}{.25in}{24pt}{.25in}{8in}{4in}}\fi}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{nomaketitle}
% The package makes a redefinition of \cs{makeinlinetitle} (originally defined
% in the web package. Using this option, the redefinition is skipped.
%    \begin{macrocode}
\newif\ifmob@maketitledefn \mob@maketitledefntrue
\DeclareOption{nomaketitle}{\mob@maketitledefnfalse}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{useforms}
% By default, links are created to \textsf{Print} the file and \textsf{Toggle Cols},
% if this option is used, form buttons are used instead. The form button will be
% set so that it is visible but does not print. (An advantage it has over links.)
%    \begin{macrocode}
\newif\ifmob@useforms \mob@useformsfalse
\DeclareOption{useforms}{\mob@useformstrue}
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}{scalefigures}
% An option suggested by Mathias M. When this option is taken, graphic images
% are scaled according to an algorithm. See the description above the definition
% of \cs{mob@adjwidth}. The commands \DescribeMacro{\scalefiguresOn}\cmd{\scalefiguresOn}
% and \DescribeMacro{\scalefiguresOff}\cmd{\scalefiguresOff} are a convenient way to
% turn the scaling of figures on and off.
% \changes{v1.2}{2012/06/28}{Added \texttt{scalefigures} and \texttt{!scalefigures}}
%    \begin{macrocode}
\newif\ifmobscalefigures\mobscalefiguresfalse
\newcommand{\scalefiguresOn}{\mobscalefigurestrue}
\newcommand{\scalefiguresOff}{\mobscalefiguresfalse}
\DeclareOption{scalefigures}{\mobscalefigurestrue}
\DeclareOption{!scalefigures}{\mobscalefiguresfalse}
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
% \textbf{Early Stop.} If \cs{ifsmartphone} is false, we stop here.
%\changes{v1.1}{2012/06/26}{added early \cs{endinput}}
%    \begin{macrocode}
\ifsmartphone\else\expandafter\endinput\fi
%    \end{macrocode}
% We require the \textsf{web} package to set the dimensions of the page, above,
% and the \textsf{eforms} package to set links, defined below.
%    \begin{macrocode}
\RequirePackage{web}
\RequirePackage{eforms}
%    \end{macrocode}
% \subsection{Set initial view}
% There seems to be a slight conflict between \textsf{aeb\_pro} and \textsf{hyperref}
% when it comes to setting some of the preferences. If \textsf{aeb\_pro} is
% loaded, we'll use \textsf{aeb\_pro}, otherwise, we use \textsf{hyperref}.
%    \begin{macrocode}
\@ifpackageloaded{aeb_pro}{%
    \DeclareInitView{%
        layoutmag={pagelayout=TwoColumnLeft,mag=FitWidth},
        windowoptions=showtitle}}{%
    \hypersetup{pdfdisplaydoctitle=true,%
        pdfstartview=FitH -32768,pdfpagelayout=TwoColumnLeft}}
%    \end{macrocode}
% \subsection{A title page}
% \DescribeMacro{\makeinlinetitle}The web defines
% \cs{makeinlinetitle}, we'll redefine it here
% for our convenience.
%    \begin{macrocode}
\ifmob@maketitledefn
\renewcommand{\makeinlinetitle}
{%
    \begingroup\parskip0pt\parindent0pt
    \par\vspace*{6pt}
    \noindent\makebox[\linewidth][c]{\bfseries
    \color{\webuniversity@color}\webuniversity}\par\kern6pt\noindent
    \makebox[\linewidth][c]{\parbox[c]{.75\linewidth}{\centering
    \bfseries\color{\webtitle@color}\webtitle}}\par\kern12pt
    \noindent\parbox{\linewidth}{\scriptsize
        \web@copyright\space\the\year\hfill\thewebemail\\
        \@date\hfill\@ifundefined{aeb@talksite}{\webversion}
            {\ifx\aeb@talksite\@empty\webversion
              \else\aeb@talksite\fi}%
        }\par
    \noindent\makebox[\linewidth]{\rule{.67\linewidth}{.4pt}}%
    \par\endgroup
}
\fi
%    \end{macrocode}
% \subsection{Redefinitions of {\LaTeX} commands}
% We redefine \cs{paragraph} and a key-value of \cs{includegraphics}
%    \begin{macrocode}
\renewcommand{\paragraph}{\edef\mob@partpgraphexp{\noexpand
    \@startsection{paragraph}{4}{0pt}%
        {\ifdim\parskip=0pt12pt\else0pt\fi}}%
        \mob@partpgraphexp{-3pt}{\bfseries}}
%    \end{macrocode}
% This is an implementation of an idea proposed by Mathias M. He notes that
% a figure that looks fine when the document is compiled for paper, is too small
% when compiled for the smartphone.  So, he proposes to double the width of the
% image up to a maximum width of \cs{textwidth}. My implementation is to redefine
% the key-value command for \cs{includegraphics} from \textsf{graphicx}, to intercept the declared width,
% and modify its value according to the above description.
%\changes{v1.1}{2012/06/26}{Added the \cs{mob@adjwidth} command to adjust the width
% of a graphic}
%
% The scaling of figures can be turned on and off by setting the switch
% \cs{ifmobscalefigures}, as appropriate.
% \changes{v1.2}{2012/06/28}{Added conditional \cs{ifmobscalefigures}}
%    \begin{macrocode}
\def\mob@adjwidth#1{\ifmobscalefigures{\dimen0=#1
    \dimen0=2\dimen0\relax
    \xdef\mob@djwidth{\expandafter\the
        \ifdim\dimen0<\textwidth
        \dimen0 \else\textwidth\fi}%
    }\else\gdef\mob@djwidth{#1}\fi
}
%    \end{macrocode}
% We intercept the width parameter, pass it to \cs{mob@adjwidth}, then
% use the result to define the graphicx command \cs{Gin@ewidth}.
%    \begin{macrocode}
\@ifpackageloaded{graphicx}{%
    \define@key{Gin}{width}{\mob@adjwidth{#1}%
        \edef\Gin@ewidth{\mob@djwidth}}%
}{}
%    \end{macrocode}
% \subsection{Some JavaScript}
% We define two functions: (1) \texttt{\_printIt()} prints
% the current document using the default printer in two columns;
% (2) \texttt{\_toggleViews()} toggles the view between single column
% and two columns. In both case we use fit width zoom type.
%    \begin{macrocode}
\begin{insDLJS}[_mobileJS]{mobile}{JS supporting mobile formatting}
var _mobileJS=true
function _printIt(){
    var pp=this.getPrintParams();
    pp.pageHandling=pp.constants.handling.nUp;
    pp.nUpPageOrder=pp.constants.nUpPageOrders.Horizontal;
    pp.nUpNumPagesH=2;
    pp.nUpPageBorder=false;
    pp.nUpAutoRotate=false;
    this.print(pp);
}
function _toggleViews() {
    this.zoomType=zoomtype.fitW;
    this.layout=(this.layout!="TwoColumnLeft")?%
"TwoColumnLeft":"OneColumn";
}
\end{insDLJS}
%    \end{macrocode}
% \subsection{Links in running header}
% \DescribeMacro{\mobPrint}\cs{mobPrint} sets the text of the print link
% and the button caption if its a push button.
% \DescribeMacro{\mobToggleCols} \cs{mobToggleCols} sets
% the text for the toggle link and the button caption if its a push
% button. \DescribeMacro{\mobPrintTip}\cs{mobPrintTip} is the tool tip
% when there's a button for the print; while \DescribeMacro{\mobToggleColsTip}
% \cs{mobToggleColsTip} does the same for the toggle button.
%    \begin{macrocode}
\newcommand{\mobPrint}[1]{\def\mob@print{#1}}
\mobPrint{Print}
\newcommand{\mobPrintTip}{Click to print this document in two-column
    format, recommended.}
\newcommand{\mobToggleCols}[1]{\def\mob@toggleCols{#1}}
\mobToggleCols{Toggle Cols}
\newcommand{\mobToggleColsTip}{Click to toggle between single-column
    and two-column page layouts.}
%    \end{macrocode}
% \paragraph*{German language.} The following are redefinitions supplied
% by a user in the German language.
%\begin{verbatim}
%\mobPrint{Drucken}
%\renewcommand{\mobPrintTip}{Zum Drucken des Dokumentes hier klicken
%   (zweispaltige Ansicht empfehlenswert).}
%\mobToggleCols{Spaltenansicht umschalten}
%\renewcommand{\mobToggleColsTip}{Zum Umschalten der Spaltenansicht
%   (einspaltig oder zweispaltig) hier klicken.}
%\end{verbatim}
% \DescribeMacro{\mobFormPresets}\cs{mobFormPresets} is used to set
% the appearance of the buttons when the \texttt{useforms} option is taken.
%    \begin{macrocode}
\newcommand{\mobFormPresets}[1]{%
    \def\mob@FormPresets{#1}}
\mobFormPresets{\S{S}\BC{}\textSize{8}\autoCenter{n}}
%    \end{macrocode}
% \DescribeMacro{\mobPrintIt}\DescribeMacro{\mobTwoCols} The commands
% \cs{mobPrintIt} sets the print link, while \cs{mobTwoCols}
% does the some for toggling. Each call their respective
% document level JS. They each have one optional parameter
% that is use to modify its appearance.
%    \begin{macrocode}
\newcommand{\mobPrintIt}[1][]{%
    \ifmob@useforms
        {\footnotesize\def\ef@btnspcr{}%
         \settoheight{\@tempdima}{\strut}%
         \settodepth{\@tempdimb}{\strut}%
         \addtolength{\@tempdima}{\@tempdimb}%
         \raisebox{-\@tempdimb}{\pushButton[#1\F{-\FPrint}
            \TU{\mobPrintTip}
            \presets{\mob@FormPresets}%
            \CA{\mob@print}\A{\JS{_printIt();}}%
         ]{mobPrintIt}{}{\@tempdima}}}\else
        \setLink[#1\A{\JS{_printIt();}}]{\mob@print}\fi
}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand{\mobTwoCols}[1][]{%
    \ifmob@useforms
        {\footnotesize\def\ef@btnspcr{}%
         \settoheight{\@tempdima}{\strut}%
         \settodepth{\@tempdimb}{\strut}%
         \addtolength{\@tempdima}{\@tempdimb}%
         \raisebox{-\@tempdimb}{\pushButton[#1\F{-\FPrint}
         \TU{\mobToggleColsTip}\presets{\mob@FormPresets}%
            \CA{\mob@toggleCols}\A{\JS{_toggleViews();}}%
         ]{mobToggleCols}{}{\@tempdima}}}\else
    \setLink[#1\A{\JS{_toggleViews();}}]{\mob@toggleCols}\fi
}
%    \end{macrocode}
% Here, we set the left header. If you want to change the
% appearance of the links, you need to execute this next
% line in the preamble with the optional parameter to change
% the appearances. This assumes the document is using
% the page style \texttt{webheadings}, as defined in \textsf{web}.
%    \begin{macrocode}
\lheader{\mobPrintIt\relax\ifmob@useforms\kern3bp
    \else\,/\,\fi\mobTwoCols\relax}
%    \end{macrocode}
% \subsection{Add a page if odd}
% \DescribeMacro{\generateEvenPage} adds one more page
% to make an even number of pages. May be redefined as needed.
%    \begin{macrocode}
\newcommand{\generateEvenPage}{\ifodd\value{page}\else
    \newpage\lheader{}\null\fi}
\AtEndDocument{\generateEvenPage}
%</package>
%    \end{macrocode}
\endinput

% iPad
% Landscape
% w: 7.75in
% h: 5.8in