-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalttex.dtx
More file actions
920 lines (854 loc) · 31.6 KB
/
alttex.dtx
File metadata and controls
920 lines (854 loc) · 31.6 KB
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
% \iffalse
%% File: alttex.dtx by Arno Trautmann, mail: arno dot trautmann at gmx dot de
%<*internal>
\iffalse
%</internal>
%<*readme>
This is an experimental LaTeX package, using the XeTeX engine, some XeLaTeX packages and unicode features to offer a new way of working with LaTeX. Well, that’s exaggerated, but still it might be a nice toy.
Read the docmentation by clicking on ”raw“ at the pdf.
To compile and use the package, just download the .dtx and compile it with XeLaTeX. Then put the resulting .sty file to a place where TeX finds it. Documentation will be generated, too, but might lack some fonts. Therefore it is offered on github as well.
Any comments are welcome! Contact me: arno dot trautmann at gmx dot de.
%</readme>
%<*internal>
\fi
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent
\preamble
EXPERIMENTAL CODE
Do not distribute this file without also distributing the
source files specified above.
Do not distribute a modified version of this file under the same name.
\endpreamble
\postamble
Copyright 2008–2010 Arno Trautmann <arno.trautmann@gmx.de>
Distributed under the LaTeX Project Public License,
verson 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" by Arno Trautmann
This work conists of this file alttex.dtx
and the derived files alttex.sty
alttex.pdf
sample.tex
and sample.pdf.
\endpostamble
\askforoverwritefalse
\generate{\file{alttex.sty}{\from{alttex.dtx}{alttex}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{alttex.ins}{\from{alttex.dtx}{batchfile}}}
\nopostamble
\generate{\file{sample.tex}{\from{alttex.dtx}{sample}}}
\nopreamble
\generate{\file{readme.markdown}{\from{alttex.dtx}{readme}}}
\endgroup
%</internal>
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{ifxetex,ifluatex}
\usepackage[english]{polyglossia}
\usepackage{
expl3,
todonotes,
hyperref,
lmodern,
xltxtra
}
\hypersetup{%
pdfborder= 0 0 0,
colorlinks=true,
linkcolor= blue,
pdftitle=altTeX
}
\def\filedate{2010/01/09}
\def\fileversion{0.c}
\title{The \textsf{alttex} package}
\author{Arno L. Trautmann\thanks{arno.trautmann@gmx.de}}
\date{Version 0.c \filedate}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage{ifthen}
%\OnlyDescription
\begin{document}
\maketitle
% The following definition has to be made at this strange position for some reasons. It checks whether the font DejaVu Sans is installed on your system or not. If so, it will be used to display some characters the lmodern font does not have. If the font is not present, you will not see the symbol, but your .sty file still will be fine.
\def\setdeja{\setmonofont[Scale=0.85]{DejaVu Sans Mono}}
\def\dejawarning{}
\newboolean{FontIsAvailable}
\def\testFontAvailability#1{
\count255=\interactionmode
\batchmode
\let\preload=\nullfont
\font\preload="#1" at 10pt
\ifx\preload\nullfont \FontIsAvailablefalse
\else \FontIsAvailabletrue \fi
\interactionmode=\count255
}
\testFontAvailability{DejaVu Sans}
\ifFontIsAvailable
\setdeja\else
\def\dejawarning{\footnotetext{\bf You do not have the font DejaVu Sans Mono installed. Get it from http://dejavu-fonts.org.\\ Your .sty file created will be fine, but in the pdf there will be some symbols missing.}}\fi
\dejawarning
This is the package |alttex| which will try to give an experimental new way to write \LaTeX{} code using the modern engines lua\TeX\ or \XeTeX. So far most of the code is done with very dirty code and actually it’s a collection of things that come into my mind during boring lectures. Maybe someone will have fun with the following code fragments.
\tableofcontents
\newpage
\part{Introduction}
\section{Why this package?}
The problem I have with \LaTeX\footnote{I’ll write \LaTeX{} instead of \XeLaTeX\ or lua\LaTeX—saves me two resp. three keystrokes. Most of the code below \emph{only} works with \XeLaTeX. If you need support for [utf8]inputenc, please contact the author. Support for lua\LaTeX\ is work in progress.} is the antique way of typing. Because most people still use a hopelessly outdated keyboard layout (»qwerty« or slightly adapted versions of that), \LaTeX{} doesn’t make use of some cool features. I’m not talking about writing chinese or arabic text, but something like the following example:
In standard \LaTeX, one has to write
\begin{verbatim}
This is the normal text, then comes the itemization:
\begin{itemize}
\item text for first item
\item \begin{itemize}
\item this is an item inside an item…
\item[$\Rightarrow$] Here an item with a formula: $\int_a^b x^2 dx$
\end{itemize}
\item and the outer itemize goes on…
\end{itemize}
\end{verbatim}
That is quite some code to write and is not very good readable. Of course, a good editor has a shortcut to save time at typing, but the code still looks more like programming than like typesetting. Using this package and having a superior keyboard layout\footnote{E.\,g. the ergonomic layout Neo: \url{http://neo-layout.org/}}, you can simply write this code and get exactly the same output:\footnote{The lmodern font I’m using here does not have the symbol for the inner item , so we change to DejaVu Sans Mono here. If you compiled this document on your computer without having DejaVu Sans Mono at hand, there might be some characters missing. Please consult the documentation online, then.}
\begin{verbatim}
This is the normal text, then comes the itemization:
• text for first item
• ‣ this is an itemize inside an item
‣[⇒] Here an item with a formula: $∫_a^b x² dx$
• and the outer itemize goes on…
And your normal text goes on…
\end{verbatim}
Well, actually I’m lying now because this is not fully implemented so far. But it’s the aim of this package to provide this – besides many, many other funny and cool things. The aim is to offer a more „wysiwyg“ way, without loosing anything of logical markup. One still can re|\def|ine the |•| if he doesn’t like the way his items look and so on. The above code is not meant to just typeset the character |•|, but this is rather a command itself to be there instead of the command |\item|.
\StopEventually{}
\clearpage
\part{Implementation: alttex.sty}
\DocInput{alttex.dtx}
\end{document}
%</driver>
%<*alttex>
% \fi
% Ok, enough blahblah, now comes the code. We begin with preamble stuff:
% \begin{macrocode}
\ProvidesPackage{alttex}
[2010/01/09 v 0.c alternative way of TeXing]
\RequirePackage{expl3}
\ExplSyntaxOn
\RequirePackage{amsmath}
% \end{macrocode}
% Checking wether \XeTeX\ or lua\TeX\ are used. (Not yet implemented, as we don’t make use of any lua\TeX-specific functionality so far. This will sure change in the future!)
% \begin{macrocode}
% \end{macrocode}
% \begin{macro}{\usepackage}
% Now, this is the first highlight. It is an extremely simple and stupid approach to load missing packages on-the-fly, just like Mik\TeX{} does. We re|\def|ine the |\usepackage| and hope, it works. Only working with texlive! If you’re using Mik\TeX{}, put a
% \begin{verbatim} \let\usepackage\altpackage\end{verbatim} into your preamble, \emph{directly} after loading |alttex|. If this does not work, delete the following lines from your |alttex.sty|.
% \begin{macrocode}
\cs_set_eq:NwN\alt_oldpackage:n\usepackage
\cs_set_eq:NwN\altusepackage:n\usepackage % to restore at document level
\cs_set:Npn\usepackage#1{
\file_if_exist:nTF{#1.sty}{
\alt_oldpackage:n{#1}
}{
\immediate\write18{tlmgr~install~#1}
}
}
% \end{macrocode}
% \end{macro}
% So far, this code seems to be a bit buggy, but it should work anyhow.
%
% Now load some nice packages and testing wether you’re running \XeLaTeX{} or not.
% \begin{macrocode}
\RequirePackage{exscale}
\RequirePackage{hhline}
% \end{macrocode}
% We need |exscale| to write really big formulae, and |ifxetex| to check wether one uses the correct engine.
% \section{Textmode}
% \subsection{no escape}
% \begin{macro}{\noescape}
% You want to write plain text. Maybe you’re annoyed by always escaping characters like \_ \^ \# \& \{ \} \$ \textasciitilde{} and so on. |\noescape| allows you to never escape anything—except the \textbackslash, which still might be used for |\textit{}| or so. Or maybe not… because the \{ \} are not escaped. Have to think about this one. Maybe the \textbackslash{} will be redefined to define \{ \} by itself.
% \begin{macrocode}
\cs_new:Npn\noescape{
\char_set_catcode:w`\_= 11%
\char_set_catcode:w`\^= 11%
\char_set_catcode:w`\#= 11%
\char_set_catcode:w`\&= 11%
%\char_set_catcode:w`\{= 11%
%\char_set_catcode:w`\}= 11%
\char_set_catcode:w`\$= 11%
\char_set_catcode:w`\~= 11%
\char_set_catcode:w`\@= 11%
\char_set_catcode:w`\%= 11
}
% \end{macrocode}
% Changing |@| is not necessary here, but it fitted in nicely, so I leave it. Using lua\TeX, one would just call another catcode table instead of these manual changes.
% \end{macro}
% \begin{macro}{\oldescape}
% Of course this has to be reset when doing anything like formula, tabular etc. Maybe I will be able to change the behaviour automatically. This idea has been inspired by a discussion on the Con\TeX{}t mailinglist.
% \begin{macrocode}
\cs_new:Npn\oldescape{
\char_set_catcode:w`\%= 14%
\char_set_catcode:w`\_= 8%
\char_set_catcode:w`\^= 7%
\char_set_catcode:w`\#= 6%
\char_set_catcode:w`\&= 4%
%\char_set_catcode:w`\{= 1%
%\char_set_catcode:w`\}= 2%
\char_set_catcode:w`\$= 3%
\char_set_catcode:w`\~= 13%
\makeatother%
}
% \end{macrocode}
% \end{macro}
% \subsection{tabular}
% The way one has to type extensive tabulars is quite complex – and the resulting code is often not easy to read. I don’t have good ideas how to change this, but I’m thinking about it. Mail me any suggestions for this!
%
% This will be the first attempt to make tabulars easier: Mostly you want an |\hline| after an |\\|. So let’s try something like:\todo{I will try to implement cool stuff from the \textsf{hhline}-package.}
% \begin{macro}{\§ for \\\hhline}
% Type |\–| (an en-dash) at the end of a line, and you get an |\hhline|. Type |\=| to get a double line
% \begin{macrocode}
\cs_set:Npn\–{\hhline}
\cs_set:Npn\={\hhline}
% \end{macrocode}
% This is shurely not a good symbol for this purpose, but I don’t have a better idea so far. At least it’s a ”bar“, so one can guess what it should do.
% \end{macro}
%
% \subsection{excel tabulars}
% \begin{macro}{\exceltabular}
% Often one usese a program to calculate tabulars of numbers. To insert it into \LaTeX, one has to do some work. Here we try to copy-paste the tabular from excel, Calc or any other program to a file mytabular.txt (or any other ending). Then you say |\exceltabular{mytabular}| (you do not need the ending, therefor it doesn’t matter) and you get the tabular in a standard format. I will extend this to enable caption, variable number of columns, kind of rule used etc. This is just a very first test.
%
% This is the definition of the command:
% \begin{macrocode}
\cs_new:Npn\exceltabular#1{
\char_set_catcode:w`\^^I=4\tex_relax:D
\alt_eolintabular:%
\begin{tabular}{|c|c|c|}\hline%
\file_input:n{#1}%
\end{tabular}%
\char_set_catcode:w`\^^M=5\tex_relax:D
}
% \end{macrocode}
% And a little helper function to make the <enter> |\active|. Again, thanks to the people on the mailinglists.
% \begin{macrocode}
\cs_new:Npn\alt_linebreak:{\\\hline}
\tex_begingroup:D
\tex_lccode:D`\~=`\^^M%
\tex_lowercase:D{%
\tex_endgroup:D
\cs_new:Npn\alt_eolintabular:{%
\char_set_catcode:w`\^^M=\active
\cs_set_eq:NwN~\alt_linebreak
}%
}
% \end{macrocode}
% \end{macro}
% \subsection{tabbing}
% This will be analog to the |\exceltabular|. You write your tabbing using tabs and <enter>. That’s it :)
% \begin{macro}{\alttabbing}
% Not yet implemented!
% \begin{macrocode}
% \end{macrocode}
%
% \end{macro}
% \section{Math stuff}
% \subsection{braces}
% \begin{macro}{\newbraces}
% \begin{macro}{\oldbraces}
% Now this is something most \LaTeX-beginners don’t recognize and wonder why the formula looks so ugly: The braces () do not fit to the hight of the formula. This can be achieved by putting |\left| and |\right| in front of the braces. But actually, this is annoying! In almost any case you want this behaviour, so this should be the standard. So we redefine the way braces are handled. With |\newbraces| the ( ) always fit. If you prefer the normal \LaTeX\ way, use |\oldbraces| to reset everything. This new behaviour should be extended to other characters like \verb~| [ { <~ and so on. Maybe in some later version.
%
% I would have never been able to implement this without the help of the mailinglist members of |tex-d-l@listserv.dfn.de|!\todo{The newbraces does \emph{not} work at the moment!}
%
% The redefinition of |\mathstrut| is necessary when using amsmath (you will use amsmath when typesetting formulae, won’t you?), because the hight of formulae is determinated by the hight of a brace. But using ( ) as |\active| characters, we need another brace here. So we take |[|. This will probably also change. But the code is working fine for ( ).\todo{Maybe one could ”temporarily hardcode“ the hight of [ and then use this…}
% \begin{macrocode}
\def\resetMathstrut@{%
\setbox\z@\hbox{%
\mathchardef\@tempa\mathcode`\[\relax
\def\@tempb##1"##2##3{\the\textfont"##3\char"}%
\expandafter\@tempb\meaning\@tempa \relax
}%
\ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@
}
{\catcode`(\active \xdef({\left\string(}}
{\catcode`)\active \xdef){\right\string)}}
\cs_new:Npn\newbraces{
\char_set_mathcode:w`("8000
\char_set_mathcode:w`)"8000
}
\cs_new:Npx\oldbraces{
\char_set_mathcode:w`(\char_value_mathcode:w`(
\char_set_mathcode:w`)\char_value_mathcode:w`)
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \subsection{huge display math}
% \begin{environment}{hugedisplaymath}
% Sometimes, especially in presentations, you might need an really big formula. Imagine two hours of struggle with transformations—and finally there is the beautiful formula. Now you can say\\
% \begin{center}|\begin{hugedisplaymath} E = mc^2 \end{hugedisplaymath}| \end{center}
% There should be several steps of size, maybe.
% \begin{macrocode}
\cs_new:Npn\hugedisplaymath{
\Huge
\begin{equation*}
}
\cs_new:Npn\endhugedisplaymath{
\end{equation*}
}
% \end{macrocode}
% \end{environment}
%
% \subsection{unicode math}
% This section will soon be given up as there is the great unicode-math package by Will Robertson which does all the math stuff much more elaborate than it is hacked here. However, I let it stand for a while as unicode-math is under development.
%
% Typing math in \TeX{} is no great fun – you have to write things like |\int| instead of |∫| and so on. Have a look at the following formula:
%
% |\int_\infty^\infty \sum_a|
%
% {∫}
% The code again is stolen and I don’t understand, why it does what it does, but it does it: The first argument is the character you want to use for “unicode math“, the second one is the \TeX-command.
% \begin{macrocode}
\ExplSyntaxOff
\def\altmath#1#2{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\add@special{#1}%
\expandafter
\xdef\csname cc\string#1\endcsname{\the\catcode`#1}%
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let
\csname ac\string#1\endcsname~%
\expandafter\gdef\expandafter~\expandafter{#2}}%
\endgroup
\global\catcode`#1\active
\else
\fi
}
\ExplSyntaxOn
% \end{macrocode}
% We will make a switch to turn this stuff on or off, so it does not interfere with the unicode-math package. This list will increase by time. If you are missing a symbol, just send me the |\altmath{X}{\Xcode}|-line. I would be very thankful if anybody could send me a whole list of symbols!
% \begin{macrocode}
\cs_new:Npn\makealtmath{
\altmath{α}\alpha
\altmath{β}\beta
\altmath{γ}\gamma
\altmath{δ}\delta
\altmath{ε}\varepsilon
\altmath{χ}\chi
\altmath{λ}\lambda
\altmath{μ}\mu
\altmath{π}\pi
\altmath{σ}\sigma
\altmath{ζ}\zeta
\altmath{⇒}\Rightarrow
\altmath{⇐}\Leftarrow
\altmath{⇔}\Leftrightarrow
\altmath{∫}\int
\altmath{∀}\forall
\altmath{∃}\exists
\altmath{∞}\infinity
\altmath{₁}{_1}
\altmath{₂}{_2}
\altmath{₃}{_3}
\altmath{₄}{_4}
\altmath{₅}{_5}
\altmath{₆}{_6}
\altmath{₇}{_7}
\altmath{₈}{_8}
\altmath{₉}{_9}
\altmath{₀}{_0}
}
% \end{macrocode}
% \subsection{Lazy underscript and superscript}
% \begin{macro}{_}
% Sometimes one has to make extensive use of subscripts and superscripts, e.\,g. when typing long formulae including tensors. Then it is a bit annoying to always write the |{}|, especially when there are only two letters in the sub/superscript. So let’s try to implement the possibility to type |$F_μν F^μν $|.
% \todo{An underscore at the end of an inline-formula has to be ended with \} or egroup. That is not nice…}
%
% First, store the actual meaning of |_| and |^| in |\oldunderscore| and |\oldhat|. \todo{The redefinition of hat does not work because TeX uses it for definition of catcodes. There has to be a really tricky way to get around that.}
% \begin{macrocode}
\cs_set_eq:NwN\oldunderscore_\tex_relax:D
\cs_set_eq:NwN\oldhat^\tex_relax:D
% \end{macrocode}
% Now set |_| as |\active| char and define it the way we want it to behave. For this, we need the space char and end-of-line char to be an egroup char. So the underscript group is ended by space or eol and we don’t need to close it explicitly. (no expl3 code here, as we are dealing with the underscore. That would mess up everything …)
% \begin{macrocode}
\ExplSyntaxOff
\catcode`\_=13
\def_{%
\ifmmode
\catcode`\ =2\relax%
\catcode`\^^M=2\relax%
\expandafter\oldunderscore\bgroup%
\else%
\textunderscore%
\fi%
}
\iffalse
This does not work so far…
\catcode`\^=13
\def^{%
\ifmmode
\catcode`\ =2\relax%
\catcode`\^^M=2\relax%
\expandafter\oldhat\bgroup%
\else%
\oldhat%
\fi%
}
\fi
% \end{macrocode}
% To give the possibility to swith between normal and |alttex| behaviour, store the new underscore.
% \begin{macrocode}
\let\advancedunderscore_
% \end{macrocode}
% And the switches. By default, |_| is active. Type |\oldUnder| to get the normal |_|. \todo{The newUnder does not work so far.}
% \begin{macrocode}
\def\oldUnder{
\global\catcode`\_=8\relax
}
\def\newUnder{
\global\let_\advancedunderscore
}
\ExplSyntaxOn
% \end{macrocode}
% \end{macro}
% \subsection{matrices}
% This is a nice idea by Alexander Koch on \url{diskussion@neo-layout.org}. Using the unicode glyphs for writing matrices, we can make writing and readig of big matrices much easier. (In Neo, one can use the compose function to write the whole matrix by 4–5 keystrokes and then fill in the elements.) For example, say in the source:
% \begin{verbatim}
% ⎧a & b⎫
% ⎛a & b⎞ ⎡a & b⎤ ⎪c & d⎪
% ⎜c & d⎟ or ⎢d & e⎥ or ⎨e & f⎬
% ⎝e & f⎠ ⎣f & g⎦ ⎪g & h⎪
% ⎩i & j⎭
% \end{verbatim}
% and the result will be a |bmatrix|, a |pmatrix| or a |\right\{ matrix \end{matrix}|, respectively. As \TeX\ is assumed to read from left-top to right-bottom, the matrices must not stand in a line, i.\,e. the following notation is \emph{not} (yet?) possible:
% \begin{verbatim}
% ⎛a & b⎞
% A = ⎜c & d⎟ = B
% ⎝e & f⎠
% \end{verbatim}
% but rather you have to write
% \begin{verbatim}
% A = ⎛a & b⎞
% ⎜c & d⎟
% ⎝e & f⎠ = B
% \end{verbatim}
% If you have a suggestion how to enable the upper solution, please contact me, that would be an awesome thing!
%
% One has to pay greatest attention to the different characters looking like |⎢⎥|. They are in fact \emph{different} for the three matrices! (But not in every case; I just hope the following code really works.)
% \begin{macrocode}
\char_set_catcode:w`\⎛13
\char_set_catcode:w`\⎞13
\char_set_catcode:w`\⎟13
\char_set_catcode:w`\⎝13
\char_set_catcode:w`\⎠13
\cs_new:Npn⎛{\begin{pmatrix}}
\cs_new:Npn⎞{\\}
\cs_new:Npn⎝{}
\cs_new:Npn⎠{\end{pmatrix}}
\cs_new:Npn⎟{\\}
\catcode`\⎡13
\catcode`\⎤13
\catcode`\⎥13
\catcode`\⎣13
\catcode`\⎦13
\cs_new:Npn⎥{\\}
\cs_new:Npn⎡{\begin{bmatrix}}
\cs_new:Npn⎤{\\}
\cs_new:Npn⎣{}
\cs_new:Npn⎦{\end{bmatrix}}
\catcode`\⎧13
\catcode`\⎫13
\catcode`\⎪13
\catcode`\⎩13
\catcode`\⎭13
\catcode`\⎬13
\cs_new:Npn⎧{\left\{\begin{matrix}}
\cs_new:Npn⎫{\\\use_none:n}
\cs_new:Npn⎩{}
\cs_new:Npn⎭{\end{matrix}\right\}}
\cs_new:Npn⎪{\\\use_none:n}
\cs_new:Npn⎬{\\\use_none:n}
% \end{macrocode}
% We need to |\use_none:n| (ignore) the next character only in this case, as the left-hand bar characters seem to be the same as the right-hand and so cause additional line breaks. This way it is robust against every strange codepoint the left-hand may have.\todo{The codepoints have to be checked very carefully! This is not what a robust solution does look like!}
% \section{Lists and such things}
% \subsection{itemize with a single character}
% \label{sec:itemize}
% \begin{macro}{• instead of \item}
% Here we use an active character (mostly a unicode character bullet •) for the whole construct. And another one for nested itemizations (like a triangular bullet \nolinebreak{\fontspec[Scale=0.8]{DejaVu Sans Mono}‣}).
%
% This works quite fine for most \LaTeX\ classes, but \emph{not for beamer}! There, the end of |itemize| has to be given explicitly. For this, just say in the preable of your document, after loading this package: |\def\•{\end{itemize}}| and use the |\•| to end the itemization.
%
% \begin{macro}{\newitemi}
% \begin{macro}{\newitemii}
% The following ugly peace of code is writen by me, defining the conditional insertion of the |\begin{itemize}|. This will be assigned to an active character using |\makeitemi| and |\makeitemii|, respectively.
% \begin{macrocode}
\cs_new:Npn\outside{o}
\cs_new:Npn\inside{i}
\cs_set_eq:NwN\insideitemizei\outside
\cs_set_eq:NwN\insideitemizeii\outside
% \end{macrocode}
% The end of itemizei and itemizeii:
% \begin{macrocode}
\cs_new:Npn\altenditemize{
\if\altlastitem 1%
\let\altlastitem0%
\else%
\end{itemize}%
\let\insideitemizei\outside%
\fi%
}
% \end{macrocode}
% Dealing with the |~| char, therefore no expl3 syntax here:
% \begin{macrocode}
%
\ExplSyntaxOff
\begingroup
\lccode`\~=`\^^M%
\lowercase{%
\endgroup
\def\makeenteractive{%
\catcode`\^^M=\active
\let~\altenditemize
}%
}
\ExplSyntaxOn
\cs_new:Npn\newitemi{%
\if_meaning:w\insideitemizei\inside%
\cs_set_eq:NN\altlastitem1%
\exp_after:wN\item%
\else:%
\begin{itemize}%
\cs_set_eq:NN\insideitemizei\inside%
\cs_set_eq:NN\altlastitem1%
\makeenteractive%
\exp_after:wN\item%
\fi:
}
\cs_new:Npn\newitemii{
\if_meaning:w\insideitemizeii\inside
\exp_after:wN\item%
\else:
\begin{itemize}
\cs_set_eq:NN\insideitemizeii\inside
\exp_after:wN\item%
\fi:
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% Ok, the following code is stolen from the |shortvrb| package, and I don’t understand anything of it. But I keep on trying… nevertheless, it’s working fine, as far as I can see.
% \begin{macro}{\makeitemi}
% \begin{macro}{\makeitemii}
% With this macro, you can define the character you want to use for first-level itemize. (Guess the sense of |\makeitemii|…) Default ist |•| for first-level and |‣| for second-level. Maybe this will be extended till fourth level. More doesn‘t seem to make any sense.
%
% Again, no expl3 due to usage of |~| here. :(
% \begin{macrocode}
\ExplSyntaxOff
\makeatletter
\def\makeitemi#1{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\add@special{#1}%
\expandafter
\xdef\csname cc\string#1\endcsname{\the\catcode`#1}%
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let
\csname ac\string#1\endcsname~%
\expandafter\gdef\expandafter~\expandafter{\newitemi}}%
\endgroup
\global\catcode`#1\active
\else
\fi
}
\def\makeitemii#1{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\add@special{#1}%
\expandafter
\xdef\csname cc\string#1\endcsname{\the\catcode`#1}%
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let
\csname ac\string#1\endcsname~%
\expandafter\gdef\expandafter~\expandafter{\newitemii}}%
\endgroup
\global\catcode`#1\active
\else
\fi
}
\ExplSyntaxOn
% \end{macrocode}
% \end{macro}\end{macro}
% Now there are the two helperfunctions – no guess what they are really doing.
% \begin{macrocode}
\cs_new:Npn\add@special#1{%
\rem@special{#1}%
\exp_after:wN\cs_gset_nopar:Npn\exp_after:wN\dospecials\exp_after:wN
{\dospecials \do #1}%
\exp_after:wN\cs_gset_nopar:Npn\exp_after:wN\@sanitize\exp_after:wN
{\@sanitize \@makeother #1}}
\cs_new:Npn\rem@special#1{%
\cs_set:Npn\do##1{%
\if_num:w`#1=`##1 \else: \exp_not:N\do\exp_not:N##1\fi:}%
\cs_set_nopar:Npx\dospecials{\dospecials}%
\tex_begingroup:D
\cs_set:Npn\@makeother##1{%
\if_num:w`#1=`##1 \else: \exp_not:N\@makeother\exp_not:N##1\fi:}%
\cs_set_nopar:Npx\@sanitize{\@sanitize}%
\tex_endgroup:D}
% \end{macrocode}
% \end{macro}
% \subsection{enumerate with a single character}
% \begin{macro}{¹, ²}
% And we do just the same stuff with |\enumerate|. But here we take the character |¹| as first level item, the |²|\footnote{Maybe this is a very stupid idea, because now the |²| cannot be used as a square in mathmode. Of course there could be a test |ifmmode|, but I rather would like to find a better character for |enumerate|.} as second level etc. This may be confusing some way, but just try it.
%
% For the implementation: copy-pasted the code above, nothing interesting so far.
% \begin{macrocode}
\cs_new:Npn\¹{\end{enumerate}}
\cs_new:Npn\²{\end{enumerate}}
\cs_set_eq:NN\insideenumi\outside
\cs_set_eq:NN\insideenumii\outside
\cs_new:Npn\newenumi{
\if_meaning:w\insideenumi\inside
\exp_after:wN\item%
\else:
\begin{enumerate}
\cs_set_eq:NN\insideenumi\inside
\exp_after:wN\item%
\fi:
}
\cs_new:Npn\newenumii{
\if_meaning:w\insideenumii\inside
\exp_after:wN\item%
\else:
\begin{enumerate}
\cs_set_eq:NN\insideenumii\inside
\exp_after:wN\item%
\fi:
}
% \end{macrocode}
% We use the same methods as above, still not understanding, what they are doing. Just changing two lines of code and hoping, everything will be fine. Again, no expl3.
% \begin{macrocode}
\ExplSyntaxOff
\makeatletter
\def\makeenumi#1{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\add@special{#1}%
\expandafter
\xdef\csname cc\string#1\endcsname{\the\catcode`#1}%
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let
\csname ac\string#1\endcsname~%
\expandafter\gdef\expandafter~\expandafter{\newenumi}}%
\endgroup
\global\catcode`#1\active
\else
\fi
}
\def\makeenumii#1{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\add@special{#1}%
\expandafter
\xdef\csname cc\string#1\endcsname{\the\catcode`#1}%
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let
\csname ac\string#1\endcsname~%
\expandafter\gdef\expandafter~\expandafter{\newenumii}}%
\endgroup
\global\catcode`#1\active
\else
\fi
}
\makeatother
\ExplSyntaxOn
% \end{macrocode}
% \end{macro}
% Finally, we set the default characters for the items and enumerations:
% \begin{macrocode}
\makeitemi•
\makeitemii‣
\makeenumi¹
\makeenumii²
% \end{macrocode}
% And that’s it.\begin{center}\Large Happy alt\TeX{}ing!\end{center}
% \section{Known Bugs}
% This should be a list of serious bugs. Please report any of them to me!
% \begin{itemize}
% \item Itemize does not work correctly in beamer. Use |\•| at the end of your itemize. (see section \ref{sec:itemize})
% \item |\exceltabular| is broken.
% \end{itemize}
% \newpage\appendix
% \section*{todo}
% Here a section with some ideas that could be implemented.
% \begin{itemize}
% \item Change |\usepackage| only with a given package-option to make it more robust.
% \item Use |²| as square in mathmode and possibly |¹| as |\footnote|?
% \item Do something to enable easy tabular
% \item If there is only one char after an |_|, there should no space be needed.
% \item Maybe there could be a ConTeXt-version of this file.
% \end{itemize}
% \iffalse
%</alttex>
% \fi
% \iffalse
%<*sample>
\documentclass{article}
\usepackage[english]{babel}
\usepackage{geometry}
\usepackage{
alttex,
blindtext,
dtklogos,
fancyhdr,
multicol,
lmodern,
shortvrb,
xltxtra
}
\MakeShortVerb|
\newenvironment{sample}[1]{
\subsection*{#1}
\hrule
\label{#1}
\begin{minipage}{\textwidth}
\begin{multicols}{3}}
{\end{multicols}
\end{minipage}\vspace{2cm}}
\fancyhead{\normalfont\qquad alttex\hfill normal \hfill result\qquad}
\pagestyle{fancy}
\setmonofont[Scale=0.8]{DejaVu Sans} % the standard fonts don’t have the nice symbols!
\title{A short sample document for the |alttex| package}
\author{Arno L. Trautmann\thanks{arno.trautmann@gmx.de}}
\date{\today}
\begin{document}
\maketitle
This document shows applications of the possibilities the |alttex| packages offers for writing code in \XeLaTeX.
There are three columns: The left one shows the input code using |alttex|, the middle one shows the corresponding ”normal“ input, and on the right-hand side there is the output of that code. The output is written in the code on the left-hand side, so I am not cheating here…\vspace{2cm}
\sample{noescape}
\noescape
\begin{verbatim}
This is a short text including
some characters like an @,
a §, 100% unescaped, even {}
and ~ or a &
without a backslash.
\end{verbaatim}
\vfill
\oldescape
\begin{verbatim}
This is a short text including
some characters like an @,
a §, 100\% unescaped, even \{\}
and \textasciitilde\ or a
\& without a backslash.
\end{verbatim}
\vfill
\noescape
This is a short text including
some characters like an @,
a §, 100% unescaped, even {}
and ~ or a &
without a backslash.
\oldescape
\endsample
\makealtmath
\sample{general math}
|\[∫_-∞ ^∞ ∀\]|
\ \vfill
|\[\int_{-\infty}^{\infty}\]|
\ \vfill
\[∫_-∞ \ \]% ^∞ ∀\]
\endsample
\sample{itemize}
\begin{verbatim}
A short sample text
• first item
• second item
‣ deeper item
‣ second deeper item
\end{itemize}
\end{itemize}
\end{verbatim}
\ \vfill
\begin{verbatim}
A short sample text
\begin{itemize}
\item first item
\item second item
\begin{itemize}
\item deeper item
\item second deeper item
\end{itemize}
\end{itemize}
\end{verbatim}
\ \vfill
A short sample text
\def\‣{\end{itemize}}
• first item
• second item
‣ deeper item
‣ second deeper item
\‣
\endsample
\sample{enumerate}
\begin{verbatim}
A short sample text
¹ first item
¹ second item
² deeper item
² second deeper item
\end{enumerate}
\end{enumerate}
\end{verbatim}
\vfill
\begin{verbatim}
A short sample text
\begin{enumerate}
\item first item
\item second item
\begin{enumerate}
\item deeper item
\item second deeper item
\end{enumerate}
\end{enumerate}
\end{verbatim}
\vfill
A short sample text
¹ first item
¹ second item
² deeper item
² second deeper item
\end{enumerate}
\end{enumerate}
\endsample
\sample{huge display math}
\begin{verbatim}
\begin{hugedisplaymath}
E = mc^2
\end{hugedisplaymath}
\[E = mc^2\]
\end{verbatim}
\vfill
\begin{verbatim}
\Huge
\[ E = mc^2\]
\normalsize
\[E = mc^2\]
\end{verbatim}
\vfill
\begin{hugedisplaymath}
E = mc^2
\end{hugedisplaymath}
\[E = mc^2\]
\endsample
\end{document}
%</sample>
% \fi
% \Finale
\endinput