summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/revquantum/revquantum.dtx
blob: 103ea3b0bf1b2788f4ca060c1946ba6166e1f77c (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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
% \iffalse meta-comment
%
% Copyright (C) 2016 by Christopher Granade <cgranade@cgranade.com>
% ---------------------------------------------------------------------------
% 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 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Christopher Granade (cgranade@cgranade.com).
%
% This work consists of the files revquantum.dtx and revquantum.ins
% and the derived filebase revquantum.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{revquantum.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{revquantum}
%<*package>
    [2017/03/15 v0.11 Misc. fixes and improved installer.]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[pretty]{revquantum}[2015/12/29]
\usepackage{xcolor}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{revquantum.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \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         \~}
%
% \changes{v0.10}{2016/09/21}{Build script fixes for CTAN submission.}
% \changes{v0.09}{2016/09/20}{wlog fix, updates to affil database.}
% \changes{v0.08}{2016/04/11}{Significant reworking to robustly configure colors and fonts in listings.}
% \changes{v0.07}{2016/04/07}{Added citeneed macro, fixed TODO spacing.}
% \changes{v0.06}{2016/04/04}{Fix for hyperref bug.}
% \changes{v0.05}{2016/04/04}{BibTeX hack for missing babel languages.}
% \changes{v0.04}{2015/12/30}{Added Color Universal Design color names, checks for incompatible packages.}
% \changes{v0.03}{2015/11/26}{Integration of stmaryrd, better docs.}
% \changes{v0.02}{2015/11/04}{Initial public version.}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \newcommand{\DescribeColor}[1]{%
%     \DescribeMacro{#1}%
%     {\color{#1} \textbullet}
%
% }
%
% \GetFileInfo{revquantum.dtx}
% \title{The \textsf{revquantum} package}
% \author{Christopher Granade \\ \url{cgranade@cgranade.com}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% \section{Introduction}
%
% The \textsf{revquantum} package provides a number of useful hacks to solve
% common annoyances with the \textsf{revtex4-1} package, and to define notation
% in common use within quantum information. In doing so, \textsf{revquantum}
% imports and configures a number of commonly-available and used packages, and
% where reasonable, provides fallbacks.
%
% The \textsf{revquantum} package also warns when users try to load packages which
% are known to be incompatible with \textsf{revtex4-1}. In particular, loading the following
% packages will cause warnings:
%
% \begin{itemize}
%     \item \textsf{subcaption}
% \end{itemize}
%
% Yes, this is a short list. It will get longer.
%
% \section{Usage}
%
% \textbf{NB:} \textsf{revquantum} must be loaded first unless |nobibtexhacks|
% is passed.
%
% \subsection{Package Options}
%
% The \textsf{revquantum} package provides several options to configure its behavior.
% These can be used in the traditional way, as optional arguments to |\usepackage|.
% For instance, this document was prepared using |\usepackage[pretty]{revquantum}|.
%
% \DescribeMacro{[final]}
%
% Removes support for TODO commands (see below), causing them to escalate from
% warnings to errors.
%
% \DescribeMacro{[pretty]}
%
% Uses the \textsf{mathpazo} package to typeset the document
% more nicely than the default for \textsf{revtex4-1} drafts.
%
% \DescribeMacro{[uselistings]}
%
% Includes the \textsf{listings} package and configures it for
% literate and math-escape notation in Python, Mathematica and MATLAB.
%
% \DescribeMacro{[nobibtexhacks]}
%
% Prevents \textsf{revquantum} from patching the \BibTeX support provided
% by \textsf{revtex4-1} to include titles.
%
% \DescribeMacro{[strict]}
%
% Causes package incompatibility warnings to become errors.
%
% \subsection{New Commands}
%
% \subsubsection{TODO Annotations}
%
% \DescribeMacro{\todo} \marg{annotation}
%
% Marks an incompleted task in a different color in the document, and raises
% a warning in the LaTeX log.
%
% \DescribeMacro{\TODO}
% \TODO
%
% \DescribeMacro{\todolist} \marg{contents}
%
% Typesets \emph{contents} as a TODO annotation, wrapped in an |{enumerate}|
% environment.
%
% \subsubsection{Mathematical Notation}
%
% This package also provides commands for notation common in quantum information.
%
% \DescribeMacro{\ii}
% \DescribeMacro{\dd}
%
% These commands typeset the imaginary unit $\ii$ and differential element $\dd$,
% respectively, in math roman.
%
% \DescribeMacro{\defeq}
%
% This command uses |\mathrel| to properly format the colon-equals operator
% as a relation operator.
%
% \DescribeMacro{\expect}
% Typesets the expectation operator $\expect$.
%
% \DescribeMacro{\id}
%
% \todo{The current implementation of id is to call openone, provided by revtex4-1,
% and thus not available when used from documentation.}
%
% \DescribeMacro{\llbracket}
% \DescribeMacro{\rrbracket}
%
% Typesets the double-square brackets commonly used to denote stabilizer code
% properties, as in $\llbracket n, k, d \rrbracket$. These commands are provided
% by |{stmaryrd}|, and are given a reasonable fallback if that package is not
% available.
%
%
%
% \subsubsection{Affiliation Database}
%
% The \textsf{revquantum} package provides commands for quickly typesetting
% affiliations, with an eye towards reducing copy-paste errors when authors have
% a nontrivial set of shared affiliations.
%
% \DescribeMacro{\newaffil} \marg{shorthand} \marg{description}
%
% The workhorse of the affiliation database is the |\newaffil| command,
% which defines a new command that expands to call the \textsf{revtex4-1}
% |\affiliation| command. For instance, |\newaffil{UFooBar}{Bar, UFoo}|
% defines a new command |\affilUFooBar| that expands to
% |\affiliation{Bar, UFoo}|.
%
% So far, the following affiliation commands are provided:
%
% \DescribeMacro{\affilTODO} Special, marks that an affiliation is not
% provided.
%
%
% \DescribeMacro{\affilEQuSUSyd} Centre for Engineered Quantum Systems, University of Sydney.
%
% \DescribeMacro{\affilEQuSMacq} Centre for Engineered Quantum Systems, Macquarie University.
%
% \DescribeMacro{\affilUSydPhys} School of Physics, University of Sydney.
%
% \DescribeMacro{\affilIQC} Institute for Quantum Computing, University of Waterloo.
%
% \DescribeMacro{\affilUWPhys} Department of Physics, University of Waterloo.
%
% \DescribeMacro{\affilUWAMath} Department of Applied Mathematics, University of Waterloo.
%
% \DescribeMacro{\affilUWChem} Department of Chemistry, University of Waterloo.
%
% \DescribeMacro{\affilPI} Perimeter Institute for Theoretical Physics.
%
% \DescribeMacro{\affilCIFAR} Canadian Institute for Advanced Research.
%
% \DescribeMacro{\affilCQuIC} Center for Quantum Information and Control, University of New Mexico.
%
% \DescribeMacro{\affilIBMTJW} IBM T. J. Watson Research Center.
%
%
% \subsubsection{Internal-Use Commands}
%
% \DescribeMacro{\booloption}
% \DescribeMacro{\newnew}
%
% These commands are used internally by \textsf{revquantum} to define
% new boolean package options, and to declare new kinds of |\newcommand|
% commands. For example, |\newnew| is used to define |\newoperator|,
% which in turn defines new commands for named mathematical operators (e.g. $\Tr$).
%
% \DescribeMacro{\sectionautorefname}
% \DescribeMacro{\algorithmautorefname}
% \DescribeMacro{\equationautorefname}
% \DescribeMacro{\lemmaautorefname}
%
% These commands configure \textsf{hyperref}'s \texttt{autoref} command
% for use with \textsf{revtex4-1}, so that \texttt{autoref} correctly
% describes Section, Algorithm, and Lemma, and also follows the standard
% notation for equation references.
%
% \DescribeMacro{\boolean{@xetex}}
%
% This boolean variable uses \textsf{iftex} to check if XeTeX is installed.
% If \textsf{iftex} is not available, then we assume plain LaTeX.
%
% \subsection{New Colors}
%
% The \textsf{revquantum} package also provides a color palette
% that is safe for colorblind readers and for printing, the
% \href{http://jfly.iam.u-tokyo.ac.jp/color/}{Color Universal
% Design} palette of Okabe and Ito.
%
% \DescribeColor{cud-black}         
% \DescribeColor{cud-orange}        
% \DescribeColor{cud-sky-blue}      
% \DescribeColor{cud-bluish-green}  
% \DescribeColor{cud-yellow}        
% \DescribeColor{cud-blue}          
% \DescribeColor{cud-vermillion}    
% \DescribeColor{cud-reddish-purple}
%
% These colors are defined as \textsf{xcolor} color names, such that they
% can be used in all packages which depend on \textsf{xcolor}. In particular,
% CUD colors can be directly used from \textsf{tikz}. To use with \textsf{tikz},
% however, \textsf{revquantum} must be loaded \emph{after} \textsf{tikz}.
%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%



%    \begin{macrocode}

\usepackage{ifthen}

%    \end{macrocode}

% \subsection{XeTeX Detection} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% We make a new boolean variable to track if XeTeX is being used.

%    \begin{macrocode}

\newboolean{@xetex}
\setboolean{@xetex}{false}
\IfFileExists{iftex.sty}{
    \wlog{[INFO] iftex loaded}
    \usepackage{iftex}
}{
    \newif\ifXeTeX
    \XeTeXfalse
}
\ifXeTeX
    \wlog{[INFO] Using XeTeX}
    \setboolean{@xetex}{true}
\else
    \setboolean{@xetex}{false}
\fi

%    \end{macrocode}


% \subsection{Notation} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% \begin{macro}{\newnew}
%    \begin{macrocode}
\newcommand{\newnew}[2]{
    \expandafter\newcommand\csname new#1\endcsname[1]{
      \expandafter\newcommand\csname ##1\endcsname{#2{##1}}
    }
}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\newnew{operator}{\operatorname}
\newnew{rm}{\mathrm}

\newoperator{Tr}
\newoperator{Cov}
\newoperator{supp}
\newoperator{diag}
\newoperator{rank}

%    \end{macrocode}
%
% \begin{macro}{\ii}
%    \begin{macrocode}
\newcommand{\ii}{\mathrm{i}} % Outside what newnew currently supports.
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\dd}
%    \begin{macrocode}
\newcommand{\dd}{\mathrm{d}} % Outside what newnew currently supports.
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}

\newrm{e}
\newrm{TVD}
\newrm{T}

%    \end{macrocode}
%
% \begin{macro}{\defeq}
%    \begin{macrocode}
\newcommand{\defeq}{\mathrel{:=}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\expect}
%    \begin{macrocode}
\newcommand{\expect}{\mathbb{E}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\id}
%    \begin{macrocode}
\newcommand{\id}{\openone}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}

%    \end{macrocode}

% We want to only conditionally use |{stmaryrd}| if it's available, and
% otherwise, hack up a few commands from that package.
%
%    \begin{macrocode}
    \IfFileExists{stmaryrd.sty}{
        \RequirePackage{stmaryrd}
    }{
        \PackageWarning{revquantum}{
            The stmaryrd package is not available,
            so some commands (e.g.: double-brackets) will look wrong.
        }
        \newcommand{\llbracket}{[\!\!\hspace{1.5pt}[}
        \newcommand{\rrbracket}{]\!\!\hspace{1.5pt}]}
    }
%    \end{macrocode}


% \subsection{Options Handling} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% We will need to define a few options to make the package nicer to use. We do
% so by making a new command, |\booloption| \marg{boolname} \marg{optionname}
% \marg{default}.
% \begin{macro}{\booloption}
%    \begin{macrocode}
\newcommand{\booloption}[3]{
    \newboolean{#1}
    \setboolean{#1}{#3}
    \ifthenelse{\equal{#3}{true}}{
%    \end{macrocode}
% Default is true, so we need a "no" option to
% turn off the new boolean.
%    \begin{macrocode}
        \DeclareOption{no#2}{\setboolean{#1}{false}}
    }{
%    \end{macrocode}
% Default is false, so we need an option to turn
% on the new boolean.
%    \begin{macrocode}
        \DeclareOption{#2}{\setboolean{#1}{true}}
    }
}
%    \end{macrocode}
% \end{macro}

% We then use this new command to define the options for \textsf{revquantum},
% |final|, |pretty|, |uselistings|, |nobibtexhacks|, and |strict|.

%    \begin{macrocode}

\booloption{@final}{final}{false}
\booloption{@pretty}{pretty}{false}
\booloption{@uselistings}{uselistings}{false}
\booloption{@bibtexhacks}{bibtexhacks}{true}
\booloption{@strict}{strict}{false}

\ProcessOptions\relax

%    \end{macrocode}

% For the |strict| option, we do one last thing and define a new macro that
% either raises a warning or an option depending on whether |strict| has been
% set as an option.

% \begin{macro}{\rq@quasiwarn}
%    \begin{macrocode}
\ifthenelse{\boolean{@strict}}{
    \newcommand{\rq@quasiwarn}{
        \PackageError{revquantum}
    }
}{
    \newcommand{\rq@quasiwarn}{
        \PackageWarning{revquantum}
    }
}
%    \end{macrocode}
% \end{macro}

% \subsection{Unforgivable BibTeX Hacks} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% These hacks include the title of each reference in the BibTeX output by
% redefining the part of \textsf{revtex4-1} on the fly which is responsible
% for writing out the bibdata. Note that these hacks \emph{must} come before
% importing packages, or else \textsf{revtex4-1} will have already written out
% its control notes.

%    \begin{macrocode}

\ifthenelse{\boolean{@bibtexhacks}}{\def\@bibdataout@aps{%
 \immediate\write\@bibdataout{%
  @CONTROL{%
   apsrev41Control,author="08",editor="1",pages="0",title="0",year="1",eprint="1"%
  }%
 }%
 \if@filesw
  \immediate\write\@auxout{\string\citation{apsrev41Control}}%
 \fi
}}{}

%    \end{macrocode}

% \subsection{Imports} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Here, we import a few other useful packages and configure them according to
% the options passed by the user. In handling the fonts specified by
% |[pretty]|, we must be careful to do so in a way that is supported by
% XeTeX.
% Note that we only load \textsf{color} if
% neither \textsf{tikz} nor \textsf{xcolor} have already been imported, and if
% we are not using \textsf{listings}. In the latter case, we will load
% \textsf{xcolor} instead so that we can make \textsf{listings} play nicer with
% our own custom palette.
% Also of
% note is that we do not import \textsf{hyperref} yet, as it must go last to avoid duplicating
% reference names.

%    \begin{macrocode}

\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{amsthm}
\RequirePackage{amssymb}
\RequirePackage{amsbsy}
\@ifpackageloaded{tikz}{}{%
    \@ifpackageloaded{xcolor}{}{%
        \ifthenelse{\boolean{@uselistings}}{}{%
            \RequirePackage[usenames,dvipsnames]{color}%
        }%
    }%
    \AtBeginDocument{%
        \@ifpackageloaded{tikz}{%
            \rq@quasiwarn{tikz loaded, but after revquantum. This may not work.}%
        }%
    }%
}
\RequirePackage{braket}
\RequirePackage{graphicx}
\RequirePackage[english]{babel}
\ifthenelse{\boolean{@pretty}}{
    \ifthenelse{\boolean{@xetex}}{
        % http://tex.stackexchange.com/a/50593
        \usepackage{fontspec}
        \usepackage{mathpazo}
        \setmainfont
         [ BoldFont       = texgyrepagella-bold.otf ,
           ItalicFont     = texgyrepagella-italic.otf ,
           BoldItalicFont = texgyrepagella-bolditalic.otf ]
         {texgyrepagella-regular.otf}
    }{
        \RequirePackage{mathpazo}
    }
}{}
\ifthenelse{\boolean{@uselistings}}{
    \RequirePackage{xcolor}
    \RequirePackage{listings}
    \RequirePackage{textcomp} % Make sure we have a ` for writing Mathematica.
}{}
\ifthenelse{\boolean{@bibtexhacks}}{
    \RequirePackage{letltxmacro}
    \RequirePackage{etoolbox}
}{}
%    \end{macrocode}

% \subsubsection{Theorem Environments}

%    \begin{macrocode}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}

%    \end{macrocode}

% \subsubsection{\textsf{algorithm} and \textsf{algpseudocode} Setup}

%    \begin{macrocode}

\RequirePackage{algorithm}
\RequirePackage{algpseudocode}
    \renewcommand{\algorithmicrequire}{\textbf{Input:}}
    \renewcommand{\algorithmicensure}{\textbf{Output:}}
    \newcommand{\inlinecomment}[1]{\Comment {\footnotesize #1} \normalsize}
    \newcommand{\linecomment}[1]{\State \(\triangleright\) {\footnotesize #1} \normalsize}

%    \end{macrocode}

% \subsubsection{\textsf{listings} Setup}

% Here, we provide special support for scientific languages like Python and Mathematica,
% as well as for legacy environments. This support consists of configuring escapes,
% quoting, providing additional keywords, etc.

%    \begin{macrocode}

\ifthenelse{\boolean{@uselistings}}{
    \definecolor{comment-color}{gray}{0.5}

    \lstset{
        basicstyle=\footnotesize,
        commentstyle=\color{comment-color},
        frame=lines,
        gobble=4,
        numbers=left,
        numberstyle=\tiny, stepnumber=5,
        numbersep=5pt,
        keywordstyle=\color{cud-bluish-green!85!black}\bfseries,
        keywordstyle={[2]\color{cud-sky-blue!75!black}},
        emphstyle=\color{cud-vermillion}
    }

    \ifthenelse{\boolean{@xetex}}{
        \RequirePackage{sourcecodepro}
        \lstset{basicstyle=\footnotesize\sourcecodepro}
    }{}

    \lstdefinestyle{matlab}{
        language=MATLAB,
        mathescape=true
    }

    \lstdefinestyle{python}{
        language=Python,
        mathescape=true,
        showstringspaces=false,
        morekeywords={as,async,await}
    }

    \lstdefinestyle{mathematica}{
        language=Mathematica,
        upquote=true, % Needed to deal with the context symbol `.'
        literate=
            {->}{$\to$}1
            {!=}{$\neq$}1
            {\\[DoubleStruckOne]}{${\id}$}1
            {\\[Sigma]}{$\sigma$}1
            {(x)}{$\otimes$}1 % CG: I have the distinct impression this will break. Badly.
    }
}{}

%    \end{macrocode}

% \subsection{Import Warnings} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The following command will cause a warning to be emitted if the package
% named by its argument is loaded. To make robust against the order in which
% packages are loaded, all such logic happens at |\begin{document}|. This
% code is adapted from the solution provided by Martin Scharrer at
% \url{http://tex.stackexchange.com/a/16200/615}.

% \begin{macro}{\rq@warnpackage}
%    \begin{macrocode}
\newcommand{\rq@warnpackage}[1]{
    \AtBeginDocument{%
        \@ifpackageloaded{#1}{%
            \rq@quasiwarn{The #1 package is known to be incompatible with revtex4-1. You may encounter problems using this package.}%
        }{}
    }
}
%    \end{macrocode}
% \end{macro}

% With this command in place, we can now issue specific warnings for individual
% ``bad'' packages.

%    \begin{macrocode}
\rq@warnpackage{subcaption}
%    \end{macrocode}


% \subsection{Slightly More Forgivable BibTeX Hacks} %%%%%%%%%%%%%%%%%%%%%%%%%

% Next, we include \href{http://tex.stackexchange.com/a/199299/615}{a solution
% suggested by egreg} for a rather annoying |{revtex4-1}| bug. In particular,
% we will set up |language={en}| as an alias for |language={english}|, so that
% |{revtex4-1}| will no longer raise |{babel}| errors for the undefined language.
% As with our unforgivable hacks, we will guard the forgivable hacks with
% the |[nobibtexhacks]| option.

% \begin{macro}{\ORIGselectlanguage}
%    \begin{macrocode}

\ifthenelse{\boolean{@bibtexhacks}}{
    \LetLtxMacro{\ORIGselectlanguage}{\selectlanguage}
    \DeclareRobustCommand{\selectlanguage}[1]{%
      \@ifundefined{alias@\string#1}
        {\ORIGselectlanguage{#1}}
        {\begingroup\edef\x{\endgroup
           \noexpand\ORIGselectlanguage{\@nameuse{alias@#1}}}\x}%
    }
}{}

%    \end{macrocode}
% \end{macro}

% \begin{macro}{\definelanguagealias}
%    \begin{macrocode}

\newcommand{\definelanguagealias}[2]{%
  \@namedef{alias@#1}{#2}%
}

%    \end{macrocode}
% \end{macro}

%    \begin{macrocode}

\definelanguagealias{en}{english}
\definelanguagealias{EN}{english}
\definelanguagealias{English}{english}

%    \end{macrocode}

% We will also redefine |\doibase| to eat any newlines following it, and to
% prefer HTTPS to HTTP. This will fix a rather annoying bug where line breaks
% in the *.bbl source can introduce extraneous spaces into the target of
% each citation's |\href|.

% \begin{macro}{\doibase}
%     \begin{macrocode}

\ifthenelse{\boolean{@bibtexhacks}}{
    % Ensure that the \doibase command is defined, just in case.
    \providecommand{\doibase}{}
    \renewcommand{\doibase}[1]{https://dx.doi.org/\ifdefempty{#1}{}{#1}} 
}{}

%     \end{macrocode}
% \end{macro}


% \subsection{TODO Support} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% These commands provide a way of marking items as needing to be done before
% the final version (denoted by the |final| package option).

% \begin{macro}{\todo}
%    \begin{macrocode}

\ifthenelse{\boolean{@final}}{
    \newcommand{\todo}[1]{%
        \PackageError{revquantum}{Unaddressed TODO}%
        \rq@todo{#1}%
    }
}{
    \newcommand{\todo}[1]{%
        \PackageWarning{revquantum}{Unaddressed TODO}%
        \rq@todo{#1}%
    }
}

%    \end{macrocode}
% \end{macro}
%
% We also define a |\citeneed| command for the special case of a missing citation.
% As per Steve Flammia's suggestion, this is formatted in analogy to the infamous
% Wikipedia annotation.
%
% \begin{macro}{\citeneed}
%     \begin{macrocode}
\ifthenelse{\boolean{@final}}{
    \newcommand{\citeneed}{%
        \PackageError{revquantum}{citation needed}%
        \rq@todo{[citation needed]}%
    }
}{
    \newcommand{\citeneed}{%
        \PackageWarning{revquantum}{citation needed}%
        \rq@todo{[citation needed]}%
    }
}
%    \end{macrocode}
% \end{macro}
%
% Both of these macros are based on the |\rq@todo| macro, which performs the
% formatting for TODOs.
%
% \begin{macro}{\rq@todo}
%    \begin{macrocode}
\newcommand{\rq@todo}[1]{%
    {\color{magenta} #1}%
}
%    \end{macrocode}
% \end{macro}
%
% We also provide a few other special cases below.
%
% \begin{macro}{\TODO}
%    \begin{macrocode}
\newcommand{\TODO}{\todo{TODO}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\todolist}
%    \begin{macrocode}
\newcommand{\todolist}[1]{\todo{
    \begin{itemize}
        #1
    \end{itemize}
}}

%    \end{macrocode}
% \end{macro}

% \subsection{Color Universal Design} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%    \begin{macrocode}
\definecolor{cud-black}         {RGB}{0,0,0}
\definecolor{cud-orange}        {RGB}{230,159,0}
\definecolor{cud-sky-blue}      {RGB}{86,180,233}
\definecolor{cud-bluish-green}  {RGB}{0,158,115}
\definecolor{cud-yellow}        {RGB}{240,228,66}
\definecolor{cud-blue}          {RGB}{0,114,178}
\definecolor{cud-vermillion}    {RGB}{213,94,0}
\definecolor{cud-reddish-purple}{RGB}{204,121,167}
%    \end{macrocode}

% \subsection{Affiliation Database} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\newaffil}
%    \begin{macrocode}
\newcommand{\newaffil}[2]{
    \expandafter\newcommand\csname affil#1\endcsname{
        \affiliation{
            #2
        }
    }
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{General Affiliations}
%
%    \begin{macrocode}

\newaffil{TODO}{\TODO}

%    \end{macrocode}
%
% \subsubsection{Australia}
%
%    \begin{macrocode}

\newaffil{EQuSUSyd}{
    Centre for Engineered Quantum Systems,
    University of Sydney,
    Sydney, NSW, Australia
}
\newaffil{EQuSMacq}{
    Centre for Engineered Quantum Systems,
    Macquarie University,
    Sydney, NSW, Australia
}
\newaffil{USydPhys}{
    School of Physics,
    University of Sydney,
    Sydney, NSW, Australia
}

%    \end{macrocode}
%
% \subsubsection{Canada}
%
%    \begin{macrocode}

\newaffil{IQC}{
    Institute for Quantum Computing,
    University of Waterloo,
    Waterloo, ON, Canada
}
\newaffil{UWPhys}{
    Department of Physics,
    University of Waterloo,
    Waterloo, ON, Canada
}
\newaffil{UWAMath}{
    Department of Applied Mathematics,
    University of Waterloo,
    Waterloo, ON, Canada
}
\newaffil{UWChem}{
    Department of Chemistry,
    University of Waterloo,
    Waterloo, ON, Canada
}
\newaffil{PI}{
    Perimeter Institute for Theoretical Physics,
    31 Caroline St. N,
    Waterloo, Ontario, Canada N2L 2Y5
}
\newaffil{CIFAR}{
    Canadian Institute for Advanced Research,
    Toronto, ON, Canada
}

%    \end{macrocode}
%
% \subsubsection{United States}
%
%    \begin{macrocode}

\newaffil{CQuIC}{
    Center for Quantum Information and Control,
    University of New Mexico,
    Albuquerque, NM 87131-0001, USA
}
\newaffil{IBMTJW}{
    IBM T. J. Watson Research Center,
    Yorktown Heights, New York 10598, USA
}


%    \end{macrocode}


% \subsection{\textsf{hyperref} Setup} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Finally, we load \textsf{hyperref} separately so that it can go last.

% Get rid of \textsf{hyperref}'s ugly boxes.
%From:http://tex.stackexchange.com/a/51349
%    \begin{macrocode}

\RequirePackage[breaklinks=true]{hyperref}

\hypersetup{
  colorlinks   = true, %Colours links instead of ugly boxes
  urlcolor     = blue, %Colour for external hyperlinks
  linkcolor    = blue, %Colour of internal links
  citecolor    = red %Colour of citations
}

%    \end{macrocode}


% \subsubsection{\textsf{autoref} Setup}
% We must declare our \textsf{autoref} configuration at the beginning
% of the document to keep other packages from clobbering it.

% \begin{macro}{\sectionautorefname}
%    \begin{macrocode}
\AtBeginDocument{%
    \def\sectionautorefname{Section}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\algorithmautorefname}
%    \begin{macrocode}
\AtBeginDocument{%
    \def\algorithmautorefname{Algorithm}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\equationautorefname}
% See http://tex.stackexchange.com/a/66150.
%    \begin{macrocode}
\AtBeginDocument{%
    \def\equationautorefname~#1\null{(#1)\null}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\lemmaautorefname}
%    \begin{macrocode}
\AtBeginDocument{%
    \newcommand{\lemmaautorefname}{Lemma}%
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput