summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/xelatex/bidi/bidituftefloat.sty
blob: 5d6ac2c3ee6a24dae9b3018de5d53334554e9dc2 (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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
%%
%% This is file `bidituftefloat.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bidi.dtx  (with options: `table,bidituftefloat.sty')
%% 
%%   __________________________________________________
%%   Copyright (c) 2009--2017  Vafa Khalighi <persian-tex@tug.org>
%% 
%%   It may be distributed and/or modified under the LaTeX Project Public License,
%%   version 1.3c or higher (your choice). The latest version of
%%   this license is at: http://www.latex-project.org/lppl.txt
%% 
%%   This work is “author-maintained” (as per LPPL maintenance status)
%%   by Vafa Khalighi.
%% 
%% 
%% \CheckSum{49116}
%% \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
%%   Lower-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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bidituftefloat}[2017/05/19 v0.2
bidi implementation of tufte float]
\RequirePackage{xifthen}
\newcommand{\@bidituftefloat@pkgname}{bidituftefloat}
\newcommand{\bidituftefloatError}[2]{\PackageError{\@bidituftefloat@pkgname}{#1}{#2}}
\newcommand{\bidituftefloatDebugInfoNL}[1]{\ifthenelse{\boolean{@bidituftefloat@debug}}{\bidituftefloatInfoNL{#1}}{}}
\newcommand{\bidituftefloatInfoNL}[1]{\PackageInfo{\@bidituftefloat@pkgname}{#1\@gobble}}
\newboolean{@bidituftefloat@reversegeometry}
\setboolean{@bidituftefloat@reversegeometry}{false}
\DeclareOption{reversegeometry}{\setboolean{@bidituftefloat@reversegeometry}{true}}
\newboolean{@bidituftefloat@afourpaper}
\DeclareOption{a4paper}{\setboolean{@bidituftefloat@afourpaper}{true}}
\newboolean{@bidituftefloat@bfivepaper}
\DeclareOption{b5paper}{\setboolean{@bidituftefloat@bfivepaper}{true}}
\newboolean{@bidituftefloat@symmetric}
\newboolean{@bidituftefloat@twoside}
\DeclareOption{twoside}{%
\@twosidetrue  \@mparswitchtrue%
\setboolean{@bidituftefloat@twoside}{true}%
\setboolean{@bidituftefloat@symmetric}{true}%
}
\DeclareOption{oneside}{%
\@twosidefalse  \@mparswitchfalse%
\setboolean{@bidituftefloat@twoside}{false}%
\setboolean{@bidituftefloat@symmetric}{false}%
}
\@ifclassloaded{book}{\ExecuteOptions{twoside}}{}
\newboolean{@bidituftefloat@debug}
\newcommand*{\@bidituftefloat@caption@justification}{\@bidituftefloat@justification@autodetect}
\ProcessOptions
%% Globally sets the length
\newcommand*{\gsetlength}[2]{%
  \setlength{#1}{#2}%
  \global#1=#1\relax%
}

%% Set the font sizes and baselines to match bidituftefloat's books
\renewcommand\normalsize{%
   \@setfontsize\normalsize\@xpt{14}%
   \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
   \abovedisplayshortskip \z@ \@plus3\p@
   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}
\normalbaselineskip=14pt
\normalsize
\renewcommand\footnotesize{%
   \@setfontsize\footnotesize\@viiipt{10}%
   \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@
   \abovedisplayshortskip \z@ \@plus\p@
   \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
   \def\@listi{\leftmargin\leftmargini
               \topsep 3\p@ \@plus\p@ \@minus\p@
               \parsep 2\p@ \@plus\p@ \@minus\p@
               \itemsep \parsep}%
   \belowdisplayskip \abovedisplayskip
}
%% Paragraph indentation and separation for marginal text
\newcommand{\@bidituftefloat@margin@par}{%
  \setlength{\RaggedRightParindent}{0.5pc}%
  \setlength{\JustifyingParindent}{0.5pc}%
  \setlength{\parindent}{0.5pc}%
  \setlength{\parskip}{0pt}%
}
\RequirePackage{ragged2e}
\ifthenelse{\boolean{@bidituftefloat@reversegeometry}}{%
\RequirePackage[letterpaper,right=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
\ifthenelse{\boolean{@bidituftefloat@afourpaper}}
  {\geometry{a4paper,right=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
  {}
\ifthenelse{\boolean{@bidituftefloat@bfivepaper}}
  {\geometry{paperwidth=176mm,paperheight=250mm,right=14.66mm,top=13.88mm,textwidth=102.66mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}}
  {}}{%
\RequirePackage[letterpaper,left=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
\ifthenelse{\boolean{@bidituftefloat@afourpaper}}
  {\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
  {}
\ifthenelse{\boolean{@bidituftefloat@bfivepaper}}
  {\geometry{paperwidth=176mm,paperheight=250mm,left=14.66mm,top=13.88mm,textwidth=102.66mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}}
  {}}
\ifthenelse{\boolean{@bidituftefloat@symmetric}}
  {}
  {\geometry{asymmetric}}% forces internal LaTeX `twoside'
\setlength\marginparpush{10pt}
%% Font for margin items
\newcommand{\@bidituftefloat@marginfont}{\normalfont\footnotesize}
\newcommand*{\@bidituftefloat@caption@font}{\@bidituftefloat@marginfont}
\newcommand*{\setcaptionfont}[1]{\renewcommand*{\@bidituftefloat@caption@font}{#1}}
\newcommand{\@bidituftefloat@justification}{\justifying}%
\setlength\abovedisplayskip{6pt plus 2pt minus 4pt}
\setlength\belowdisplayskip{6pt plus 2pt minus 4pt}
\newboolean{@bidituftefloat@changepage}
\IfFileExists{changepage.sty}{%
  \bidituftefloatDebugInfoNL{Found changepage.sty}
  \RequirePackage[strict]{changepage}
  \setboolean{@bidituftefloat@changepage}{true}
}{%
  \bidituftefloatDebugInfoNL{Found chngpage.sty}
  \RequirePackage[strict]{chngpage}
  \setboolean{@bidituftefloat@changepage}{false}
}
\newboolean{@bidituftefloat@odd@page}
\setboolean{@bidituftefloat@odd@page}{true}
\newcommand*{\@bidituftefloat@checkoddpage}{%
  \checkoddpage%
  \ifthenelse{\boolean{@bidituftefloat@changepage}}{%
    \ifoddpage%
      \setboolean{@bidituftefloat@odd@page}{true}%
    \else%
      \setboolean{@bidituftefloat@odd@page}{false}%
    \fi%
  }{%
    \ifcpoddpage%
      \setboolean{@bidituftefloat@odd@page}{true}%
    \else%
      \setboolean{@bidituftefloat@odd@page}{false}%
    \fi%
  }%
}
\newlength{\@bidituftefloat@overhang}% used by the fullwidth environment and the running heads
\newlength{\@bidituftefloat@fullwidth}
\newlength{\@bidituftefloat@caption@fill}
\newcommand{\bidituftefloatRecalculate}{%
  \setlength{\@bidituftefloat@overhang}{\marginparwidth}
  \addtolength{\@bidituftefloat@overhang}{\marginparsep}

  \setlength{\@bidituftefloat@fullwidth}{\textwidth}
  \addtolength{\@bidituftefloat@fullwidth}{\marginparsep}
  \addtolength{\@bidituftefloat@fullwidth}{\marginparwidth}

  \setlength{\@bidituftefloat@caption@fill}{\textwidth}
  \addtolength{\@bidituftefloat@caption@fill}{\marginparsep}
}
\AtBeginDocument{\bidituftefloatRecalculate}
\RequirePackage{optparams}%  provides multiple optional arguments for commands
\RequirePackage{placeins}
\newsavebox{\@bidituftefloat@margin@floatbox}
\newenvironment{@bidituftefloat@margin@float}[2][-1.2ex]%
  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  \begin{lrbox}{\@bidituftefloat@margin@floatbox}%
  \begin{minipage}{\marginparwidth}%
    \@bidituftefloat@caption@font%
    \def\@captype{#2}%
    \hbox{}\vspace*{#1}%
    \@bidituftefloat@caption@justification%
    \@bidituftefloat@margin@par%
    \noindent%
  }
  {\end{minipage}%
  \end{lrbox}%
  \marginpar{\usebox{\@bidituftefloat@margin@floatbox}}%
  }
\newenvironment{marginfigure}[1][-1.2ex]%
  {\begin{@bidituftefloat@margin@float}[#1]{figure}}
  {\end{@bidituftefloat@margin@float}}
\newenvironment{margintable}[1][-1.2ex]%
  {\begin{@bidituftefloat@margin@float}[#1]{table}}
  {\end{@bidituftefloat@margin@float}}
\newcommand*{\@bidituftefloat@justification@autodetect}{\justifying}%

\newcommand{\@bidituftefloat@float@debug@info}{}% contains debug info generated as the float is processed
\newcommand{\@bidituftefloat@float@debug}[1]{% adds debug info to the queue for output
  \ifthenelse{\equal{\@bidituftefloat@float@debug@info}{}}%
    {\def\@bidituftefloat@float@debug@info{#1}}%
    {\g@addto@macro\@bidituftefloat@float@debug@info{\MessageBreak#1}}%
}
\newcommand{\floatalignment}{x}% holds the current float alignment (t, b, h, p)
\newcommand{\setfloatalignment}[1]{\global\def\floatalignment{#1}\@bidituftefloat@float@debug{Forcing position: [#1]}}% manually sets the float alignment
\newboolean{@bidituftefloat@float@recto}
\newcommand{\forcerectofloat}{\GlobalSetBoolean{@bidituftefloat@float@recto}{true}\@bidituftefloat@float@debug{Forcing page: [recto]}}
\newcommand{\forceversofloat}{\GlobalSetBoolean{@bidituftefloat@float@recto}{false}\@bidituftefloat@float@debug{Forcing page: [verso]}}
\newsavebox{\@bidituftefloat@figure@box}
\newsavebox{\@bidituftefloat@caption@box}
\let\@bidituftefloat@orig@float\@float
\let\@bidituftefloat@orig@endfloat\end@float
\newlength{\@bidituftefloat@caption@vertical@offset}
\setlength{\@bidituftefloat@caption@vertical@offset}{0pt}
\newcommand{\@bidituftefloat@stored@shortcaption}{}
\newcommand{\@bidituftefloat@stored@caption}{}
\newcommand{\@bidituftefloat@stored@label}{}
\long\def\@bidituftefloat@caption[#1][#2]#3{%
  \ifthenelse{\isempty{#1}}%
    {\gdef\@bidituftefloat@stored@shortcaption{#3}}%
    {\gdef\@bidituftefloat@stored@shortcaption{#1}}%
  \gsetlength{\@bidituftefloat@caption@vertical@offset}{-#2}% we want a positive offset to lower captions
  \gdef\@bidituftefloat@stored@caption{#3}%
}
\newcommand{\@bidituftefloat@label}[1]{%
  \gdef\@bidituftefloat@stored@label{#1}%
}
\newcommand{\@bidituftefloat@fps}{}
\newboolean{@bidituftefloat@float@star}
\newlength{\@bidituftefloat@float@contents@width}
\newenvironment{@bidituftefloat@float}[3][htbp]%
  {% begin @bidituftefloat@float
    % Should this float be full-width or just text-width?
    \ifthenelse{\equal{#3}{star}}%
      {\GlobalSetBoolean{@bidituftefloat@float@star}{true}}%
      {\GlobalSetBoolean{@bidituftefloat@float@star}{false}}%
    % Check page side (recto/verso) and store detected value -- can be overriden in environment contents
    \@bidituftefloat@checkoddpage%
    \ifthenelse{\boolean{@bidituftefloat@odd@page}}%
      {\GlobalSetBoolean{@bidituftefloat@float@recto}{true}\@bidituftefloat@float@debug{Detected page: [recto/odd]}}%
      {\GlobalSetBoolean{@bidituftefloat@float@recto}{false}\@bidituftefloat@float@debug{Detected page: [verso/even]}}%
    % If the float placement specifier is 'b' and only 'b', then bottom-align the mini-pages, otherwise top-align them.
    \renewcommand{\@bidituftefloat@fps}{#1}%
    \@bidituftefloat@float@debug{Allowed positions: [#1]}%
    \ifthenelse{\equal{#1}{b}\OR\equal{#1}{B}}%
      {\renewcommand{\floatalignment}{b}\@bidituftefloat@float@debug{Presumed position: [bottom]}}%
      {\renewcommand{\floatalignment}{t}\@bidituftefloat@float@debug{Presumed position: [top]}}%
    % Capture the contents of the \caption and \label commands to use later
    \global\let\@bidituftefloat@orig@caption\caption%
    \global\let\@bidituftefloat@orig@label\label%
    \renewcommand{\caption}{\optparams{\@bidituftefloat@caption}{[][0pt]}}%
    \renewcommand{\label}[1]{\@bidituftefloat@label{##1}}%
    % Handle subfigure package compatibility
    \ifthenelse{\boolean{@bidituftefloat@packages@subfigure}}{%
      \bidi@patchcmd{\subfigure}{%
      \let\subfig@oldlabel=\label
      }{%
      \let\subfig@oldlabel=\@bidituftefloat@orig@label
      }
      {}
      {}
      \let\subtable=\subfigure
    }{}% subfigure package is not loaded
    \@bidituftefloat@orig@float{#2}[#1]%
    \ifthenelse{\boolean{@bidituftefloat@float@star}}%
      {\setlength{\@bidituftefloat@float@contents@width}{\@bidituftefloat@fullwidth}}%
      {\setlength{\@bidituftefloat@float@contents@width}{\textwidth}}%
    \begin{lrbox}{\@bidituftefloat@figure@box}%
      \begin{minipage}[\floatalignment]{\@bidituftefloat@float@contents@width}\hbox{}%
  }{% end @bidituftefloat@float
      \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
      \end{minipage}%
    \end{lrbox}%
    % build the caption box
    \begin{lrbox}{\@bidituftefloat@caption@box}%
      \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
        \ifthenelse{\NOT\equal{\@bidituftefloat@stored@caption}{}}{\@bidituftefloat@orig@caption[\@bidituftefloat@stored@shortcaption]{\@bidituftefloat@stored@caption}}{}%
        \ifthenelse{\NOT\equal{\@bidituftefloat@stored@label}{}}{\@bidituftefloat@orig@label{\@bidituftefloat@stored@label}}{}%
        \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
      \end{minipage}%
    \end{lrbox}%
    % now typeset the stored boxes
    \begin{fullwidth}%
      \begin{minipage}[\floatalignment]{\linewidth}%
        \ifthenelse{\boolean{@bidituftefloat@float@star}}%
          {\@bidituftefloat@float@fullwidth[\@bidituftefloat@caption@vertical@offset]{\@bidituftefloat@figure@box}{\@bidituftefloat@caption@box}}%
          {\@bidituftefloat@float@textwidth[\@bidituftefloat@caption@vertical@offset]{\@bidituftefloat@figure@box}{\@bidituftefloat@caption@box}}%
      \end{minipage}%
    \end{fullwidth}%
    \@bidituftefloat@orig@endfloat% end original LaTeX float environment
    % output debug info
    \ifthenelse{\boolean{@bidituftefloat@debug}}{%
      \typeout{^^J^^J----------- bidituftefloat package float information ----------}%
      \ifthenelse{\equal{\@bidituftefloat@stored@label}{}}%
        {\typeout{Warning: Float unlabeled!}}%
        {\typeout{Float label: [\@bidituftefloat@stored@label]}}%
      \typeout{Page number: [\thepage]}%
      \def\MessageBreak{^^J}%
      \typeout{\@bidituftefloat@float@debug@info}%
      \ifthenelse{\boolean{@bidituftefloat@symmetric}}%
        {\typeout{Symmetric: [true]}}%
        {\typeout{Symmetric: [false]}}%
      \typeout{----------------------------------------------------^^J^^J}%
    }{}%
    % reset commands and temp boxes and captions
    \gdef\@bidituftefloat@float@debug@info{}%
    \let\caption\@bidituftefloat@orig@caption%
    \let\label\@bidituftefloat@orig@label%
    \begin{lrbox}{\@bidituftefloat@figure@box}\hbox{}\end{lrbox}%
    \begin{lrbox}{\@bidituftefloat@caption@box}\hbox{}\end{lrbox}%
    \gdef\@bidituftefloat@stored@shortcaption{}%
    \gdef\@bidituftefloat@stored@caption{}%
    \gdef\@bidituftefloat@stored@label{}%
    \gsetlength{\@bidituftefloat@caption@vertical@offset}{0pt}% reset caption offset
  }
\newcommand{\@bidituftefloat@float@textwidth}[3][0pt]{%
  \ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}\OR\boolean{@bidituftefloat@float@recto}}{%
    % asymmetric or page is odd, so caption is on the right
    \hbox{%
      \usebox{#2}%
      \hspace{\marginparsep}%
      \smash{\raisebox{#1}{\usebox{#3}}}%
    }
    \@bidituftefloat@float@debug{Caption position: [right]}%
  }{% symmetric pages and page is even, so caption is on the left
    \hbox{%
      \smash{\raisebox{#1}{\usebox{#3}}}%
      \hspace{\marginparsep}%
      \usebox{#2}%
    }
    \@bidituftefloat@float@debug{Caption position: [left]}%
  }%
}
\newcommand{\@bidituftefloat@float@fullwidth}[3][0pt]{%
  \ifthenelse{\equal{\floatalignment}{b}}%
    {% place caption above figure
      \ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}\OR\boolean{@bidituftefloat@float@recto}}%
        {\hfill\smash{\raisebox{#1}{\usebox{#3}}}\par\usebox{#2}\@bidituftefloat@float@debug{Caption position: [above right]}}% caption on the right
        {\smash{\raisebox{#1}{\usebox{#3}}}\hfill\par\usebox{#2}\@bidituftefloat@float@debug{Caption position: [above left]}}% caption on the left
    }{% place caption below figure
      \ifthenelse{\NOT\boolean{@bidituftefloat@symmetric}\OR\boolean{@bidituftefloat@float@recto}}%
        {\usebox{#2}\par\hfill\smash{\raisebox{#1}{\usebox{#3}}}\@bidituftefloat@float@debug{Caption position: [below right]}}% caption on the right
        {\usebox{#2}\par\smash{\raisebox{#1}{\usebox{#3}}}\hfill\@bidituftefloat@float@debug{Caption position: [below left]}}% caption on the left
    }%
}
\renewenvironment{figure}[1][htbp]%
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{figure}{}}
  {\end{@bidituftefloat@float}}
\renewenvironment{table}[1][htbp]
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{table}{}}
  {\end{@bidituftefloat@float}}
\renewenvironment{figure*}[1][htbp]%
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{figure}{star}}
  {\end{@bidituftefloat@float}}
\renewenvironment{table*}[1][htbp]%
  {\ifvmode\else\unskip\fi\begin{@bidituftefloat@float}[#1]{table}{star}}
  {\end{@bidituftefloat@float}}
\newenvironment{fullwidth}
  {\ifthenelse{\boolean{@bidituftefloat@symmetric}}%
     {\ifthenelse{\boolean{@bidituftefloat@changepage}}{\begin{adjustwidth*}{}{-\@bidituftefloat@overhang}}{\begin{adjustwidth}[]{}{-\@bidituftefloat@overhang}}}%
     {\begin{adjustwidth}{}{-\@bidituftefloat@overhang}}%
  }%
  {\ifthenelse{\boolean{@bidituftefloat@symmetric}}%
    {\ifthenelse{\boolean{@bidituftefloat@changepage}}{\end{adjustwidth*}}{\end{adjustwidth}}}%
    {\end{adjustwidth}}%
  }
\long\def\@caption#1[#2]#3{%
  \par%
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  \begingroup%
    \@parboxrestore%
    \if@minipage%
      \@setminipage%
    \fi%
    \@bidituftefloat@caption@font\@bidituftefloat@caption@justification%
    \noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
    %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
%%
\DeclareRobustCommand{\@biditufteheading@newlinetospace}{%
  \@ifstar{\@biditufteheading@newlinetospace@i}{\@biditufteheading@newlinetospace@i}%
}
\def\@biditufteheading@newlinetospace@i{%
  \ifdim\lastskip>\z@\else\space\fi
  \ignorespaces%
}
\DeclareRobustCommand{\newlinetospace}[1]{%
  \let\@biditufteheading@orig@cr\\% save the original meaning of \\
  \def\\{\@biditufteheading@newlinetospace}% turn \\ and \\* into \space
  \let\newline\\% turn \newline into \space
  #1%
  \let\\\@biditufteheading@orig@cr% revert to original meaning of \\
}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\AtBeginDocument{%
  \ifthenelse{\boolean{@bidituftefloat@symmetric}}
    {\fancyhfoffset[LE,RO]{\@bidituftefloat@overhang}}
    {\fancyhfoffset[RE,RO]{\@bidituftefloat@overhang}}
}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{} % clear header and footer fields
    \ifthenelse{\boolean{@bidituftefloat@symmetric}}
    {\fancyhead[LE]{\thepage\quad\textsl{\newlinetospace{\plainauthor}}}%
    \fancyhead[RO]{\textsl{\newlinetospace{\plaintitle}}\quad\thepage}}%
    {\fancyhead[RE,RO]{\textsl{\newlinetospace{\plaintitle}}\quad\thepage}}%
\fancypagestyle{plain}{
  \fancyhf{} % clear header and footer fields
  % Uncomment the following five lines of code if you want the opening page
  % of the chapter to express the folio in the lower outside corner.
  %  \ifthenelse{\boolean{@bidituftefloat@symmetric}}
  %  {\fancyfoot[LE,RO]{\thepage}}
  %  {\fancyfoot[RE,RO]{\thepage}}
}
\fancypagestyle{empty}{
  \fancyhf{} % clear header and footer fields
}
\def\morefloats{% provides a total of 52 floats
  \ifthenelse{\isundefined{\bx@S}}{%
    \bidituftefloatDebugInfoNL{Adding 34 more float slots.}
    \newinsert\bx@S
    \newinsert\bx@T
    \newinsert\bx@U
    \newinsert\bx@V
    \newinsert\bx@W
    \newinsert\bx@X
    \newinsert\bx@Y
    \newinsert\bx@Z
    \newinsert\bx@a
    \newinsert\bx@b
    \newinsert\bx@c
    \newinsert\bx@d
    \newinsert\bx@e
    \newinsert\bx@f
    \newinsert\bx@g
    \newinsert\bx@h
    \newinsert\bx@i
    \newinsert\bx@j
    \newinsert\bx@k
    \newinsert\bx@l
    \newinsert\bx@m
    \newinsert\bx@n
    \newinsert\bx@o
    \newinsert\bx@p
    \newinsert\bx@q
    \newinsert\bx@r
    \newinsert\bx@s
    \newinsert\bx@t
    \newinsert\bx@u
    \newinsert\bx@v
    \newinsert\bx@w
    \newinsert\bx@x
    \newinsert\bx@y
    \newinsert\bx@z
    \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
                    \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
                    \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
                    \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
                    \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
                    \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
                    \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
                    \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
                    \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
                    \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
                    \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
                    \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z}%
  }{% we've already added another 34 floats, so we'll add 26 more, but that's it!
    \ifthenelse{\isundefined{\bx@AA}}{%
      \bidituftefloatDebugInfoNL{Adding 26 more float slots.}
      \newinsert\bx@AA
      \newinsert\bx@BB
      \newinsert\bx@CC
      \newinsert\bx@DD
      \newinsert\bx@EE
      \newinsert\bx@FF
      \newinsert\bx@GG
      \newinsert\bx@HH
      \newinsert\bx@II
      \newinsert\bx@JJ
      \newinsert\bx@KK
      \newinsert\bx@LL
      \newinsert\bx@MM
      \newinsert\bx@NN
      \newinsert\bx@OO
      \newinsert\bx@PP
      \newinsert\bx@QQ
      \newinsert\bx@RR
      \newinsert\bx@SS
      \newinsert\bx@TT
      \newinsert\bx@UU
      \newinsert\bx@VV
      \newinsert\bx@WW
      \newinsert\bx@XX
      \newinsert\bx@YY
      \newinsert\bx@ZZ
      \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
                      \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
                      \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
                      \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
                      \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
                      \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
                      \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
                      \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
                      \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
                      \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
                      \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
                      \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z
                      \@elt\bx@AA\@elt\bx@BB\@elt\bx@CC\@elt\bx@DD\@elt\bx@EE
                      \@elt\bx@FF\@elt\bx@GG\@elt\bx@HH\@elt\bx@II\@elt\bx@JJ
                      \@elt\bx@KK\@elt\bx@LL\@elt\bx@MM\@elt\bx@NN
                      \@elt\bx@OO\@elt\bx@PP\@elt\bx@QQ\@elt\bx@RR
                      \@elt\bx@SS\@elt\bx@TT\@elt\bx@UU\@elt\bx@VV
                      \@elt\bx@WW\@elt\bx@XX\@elt\bx@YY\@elt\bx@ZZ}%
    }{%
      \bidituftefloatError{You may only call \string\morefloats\space twice. See the\MessageBreak bidituftefloat package documentation for other workarounds}
        {There are already 78 float slots allocated. Try using \string\FloatBarrier\space or\MessageBreak \string\clearpage\space to place some floats before creating more.}
    }%
  }%
}
\newboolean{@bidituftefloat@packages@subfigure}
\setboolean{@bidituftefloat@packages@subfigure}{false}
\AtBeginDocument{%
  \@ifpackageloaded{subfigure}
    {\GlobalSetBoolean{@bidituftefloat@packages@subfigure}{true}}
    {\GlobalSetBoolean{@bidituftefloat@packages@subfigure}{false}}%
}
\AtBeginDocument{%
  \@ifpackageloaded{float}{%
    % Save the redefined float environment (instead of the LaTeX float environment)
    \let\@bidituftefloat@orig@float\@float
    \let\@bidituftefloat@orig@endfloat\end@float

    % Define Tuftian float styles (with the caption in the margin)
    \newcommand{\floatc@bidituftefloatplain}[2]{%
      \begin{lrbox}{\@bidituftefloat@caption@box}%
        \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
          \@bidituftefloat@caption@font{\@fs@cfont #1:} #2\par%
        \end{minipage}%
      \end{lrbox}%
      \smash{\hspace{\@bidituftefloat@caption@fill}\usebox{\@bidituftefloat@caption@box}}%
    }
    \newcommand{\fs@bidituftefloatplain}{%
      \def\@fs@cfont{\@bidituftefloat@caption@font}%
      \let\@fs@capt\floatc@bidituftefloatplain%
      \def\@fs@pre{}%
      \def\@fs@post{}%
      \def\@fs@mid{}%
      \let\@fs@iftopcapt\iftrue%
    }
    \let\fs@bidituftefloatplaintop=\fs@bidituftefloatplain
    \let\floatc@bidituftefloatplaintop=\floatc@bidituftefloatplain
    \newcommand\floatc@bidituftefloatruled[2]{%
      {\@fs@cfont #1} #2\par%
    }
    \newcommand\fs@bidituftefloatruled{%
      \def\@fs@cfont{\@bidituftefloat@caption@font}%
      \let\@fs@capt\floatc@bidituftefloatplain%
      \def\@fs@pre{\hrule height.8pt depth0pt width\textwidth \kern2pt}%
      \def\@fs@post{\kern2pt\hrule width\textwidth\relax}%
      \def\@fs@mid{}%
      \let\@fs@iftopcapt\iftrue%
    }
    \newcommand\fs@bidituftefloatboxed{%
      \def\@fs@cfont{}%
      \let\@fs@capt\floatc@bidituftefloatplain%
      \def\@fs@pre{%
        \setbox\@currbox\vbox{\hbadness10000
        \moveleft3.4pt\vbox{\advance\hsize by6.8pt
          \hrule \hbox to\hsize{\vrule\kern3pt
            \vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt\vrule}\hrule}}
      }%
      \def\@fs@mid{\kern2pt}%
      \def\@fs@post{}%
      \let\@fs@iftopcapt\iftrue%
    }
  }{%
    % Nothing to do
  }
}
\AtBeginDocument{%
  \@ifpackageloaded{algorithm}{%
    % Set the float style to the Tuftian version
    \ifthenelse{\equal{\ALG@floatstyle}{plain}\OR\equal{\ALG@floatstyle}{ruled}\OR\equal{\ALG@floatstyle}{boxed}}{%
      \bidituftefloatInfoNL{Switching algorithm float style from \ALG@floatstyle\MessageBreak to bidituftefloat\ALG@floatstyle}%
      \floatstyle{bidituftefloat\ALG@floatstyle}%
      \restylefloat{algorithm}%
    }{}%
  }{%
    % Nothing to do
  }
}
\PassOptionsToPackage{caption=false}{subfig}
\endinput
%%
%% End of file `bidituftefloat.sty'.