-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlwtverb.dtx
1249 lines (1194 loc) · 51.1 KB
/
lwtverb.dtx
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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
% Copyright (C) 2020 by Alexander Vasilevsky (kalaider) <a.kalaider@yandex.ru>
% ---------------------------------------------------------------------------
% 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 Alexander Vasilevsky.
%
% This work consists of the files lwtverb.dtx and lwtverb.ins
% and the derived filebase lwtverb.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{lwtverb.dtx}
% \pkg{hyperref} loads \pkg{url} internally,
% here is the best we can do for now
\PassOptionsToPackage{obeyspaces, spaces}{url}
\PassOptionsToPackage{obeyspaces, spaces}{xurl}
\documentclass{l3doc}
% ShortVerb interferes with {\thispkg}
\AtBeginDocument
{
\DeleteShortVerb \"
\DeleteShortVerb \|
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{microtype}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{float}
\usepackage{enumitem}
\usepackage{mdframed}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{xurl}
\usepackage{lwtverb}[2020/07/16]
\setlength{\parindent}{0pt}
\addtolength{\parskip}{0.5\baselineskip}
\mdfdefinestyle{example}{
skipbelow=0cm,
}
\newmdenv[style=example]{examplebox}
\captionsetup[table]{justification=centering}
\EnableCrossrefs
\RecordChanges
\newcommand\opt[1]{\textsf{#1}} % typeset package options
\def\t{\lwttt}
\def\c{\lwtcode}
\def\thispkg{\pkg{lwtverb}}
\newenvironment{exampletbl}{%
\setlength\tabcolsep{0pt}%
\setlength{\extrarowheight}{1ex}%
\begin{tabular}}{\end{tabular}}
\newcolumntype{P}[1]{>{\begin{minipage}[t]{#1}\arraybackslash} c <{\vspace{1ex}\end{minipage}}}
\newcolumntype{F}{P{0.3\textwidth}}
\DeclareUrlCommand\xurltt{\urlstyle{tt}}
\begin{document}
\DocInput{lwtverb.dtx}
\PrintChanges
\end{document}
%</driver>
%<*package>
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{lwtverb}[2020/07/16 1.0 Yet another package for inline verbatim typesetting]
\RequirePackage{xparse} % powerful command syntax
\RequirePackage{xkeyval} % key-value options for package
\RequirePackage{options} % key-value options for commands
\RequirePackage{fancyvrb} % superior to detokenize
\RequirePackage{fvextra} % superior to detokenize
%</package>
% \fi
%
% \changes{1.0}{2020/07/16}{The first version}
%
% \providecommand*{\url}{\texttt}
% \title{The \pkg{lwtverb} package}
% \author{Alexander Vasilevsky (kalaider) \\ \url{a.kalaider@yandex.ru}}
%
% \maketitle
% \section{Introduction}
%
% There are many approaches to \t{text written in typewriter font}.
% Basic approach of using just \cs{tt} or \cs{texttt} does not support
% hyphenation and cannot be hard-wrapped, potentially causing overfull
% hbox warnings. Moreover, it is almost inappropriate for typesetting
% code as all special characters must be escaped manually.
%
% Verbatim-like commands help here but they fail to break properly
% (\cs{verb}), extra fragile (cannot be used in section title, captions,
% etc.) or produce too ragged results (\cs{Verb} from \pkg{fancyvrb}
% with \t{breaklines} and \t{breakanywhere} options from \pkg{fvextra}).
% \pkg{minted} does not support breaking inline code at all. \pkg{url} or
% \pkg{xurl}-based solutions handle special characters inconsistently
% and have some limitations.
%
% {\thispkg} tries to provide \textit{robust} (just as \cs{Verb} with the help of
% \pkg{fvextra} is) command for \textit{breakable} and \textit{justifiable}
% inline verbatim text. What follows next is side-by-side comparison of
% different \cs{lwtverb} variants and \cs{lwtverb} with other viable
% approaches.
%
% \Cref{sec:features} describes features {\thispkg} provides.
% \Cref{sec:examples} shows a number of usage examples, some
% spacing tweaks ``in action'', comparison to alternative approaches.
% \Cref{sec:usage} and \cref{sec:options} describe command
% usage and available options. See \cref{sec:alternatives} for
% textual comparison to other approaches and \cref{sec:limitations}
% to learn about {\thispkg} limitations.
% \section{Features}\label{sec:features}
%
% {\thispkg} provides a number of features useful for typesetting
% code and regular text in typewriter font. This section duscusses
% what it can. See \cref{sec:limitations} for what it cannot.
%
% \begin{itemize}
% \item Justifiable and breakable text in typewriter font.
% \item Line break can be marked with hyphen or any pair
% of user-provided symbols.
% \item If line break occurs at the space character, line
% break is not indicated.
% \item Subsequent spaces can be leaved as is, collapsed to
% a single space or removed entirely. If line break
% occurs between two space characters, it is configuration
% dependent whether thay are removed or retained verbatim.
% \item Individual characters can be decorated. A variant of
% decoration function takes two arguments: the current
% character being typeset and its predecessor.
% \item Spaces can be replaces with custom characters so they
% can be highlighted and thus preserved.
% \item The implementation higly relies on \pkg{fvextra}, so
% curly-braced versions of \cs{lwtverb} and \cs{lwtcode}
% commands are robust just as curly-braced version of
% \cs{Verb}. Other provided commands (\cs{lwttt},
% \cs{justtt}) are initially robust.
% \end{itemize}
% \section{Examples}\label{sec:examples}
%
% \begin{table}[H]
% \centering
% \begin{exampletbl}{*{3}{|F| p{1em}}}
% Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. &&
% Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. &&
% Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
% \end{exampletbl}
% \caption[]{Here is how normal {\LaTeX} renders the same text three times (just for comparison)}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{exampletbl}{*{3}{|F| p{1em}}}
% \c|\lwttt[b]{...}| &&
% \c|\lwttt[h]{...}| &&
% \c|\lwttt[w]{...}| \\\hline
% \lwttt[b]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[h]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[w]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.}
% \end{exampletbl}
% \caption[]{Here is how \thispkg's \cs{lwttt} renders the same text with different options applied: \t{breakline}, \t{hyphenate} and \t{wrapline}}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{exampletbl}{*{3}{|F| p{1em}}}
% \c!\lwtverb|...|! &&
% \c!\verb|...|! &&
% \c!\Verb[breaklines, breakanywhere]|...|! \\\hline
% \lwtverb|Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.| &&
% \verb|Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.| &&
% \Verb[breaklines, breakanywhere]|Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.|\\
% \lwtverb|With superduperveeerylooong words and words_with_special_characters.| &&
% \verb|With superduperveeerylooong words and words_with_special_characters.| &&
% \Verb[breaklines, breakanywhere]|With superduperveeerylooong words and words_with_special_characters.|
% \end{exampletbl}
% \caption[]{Comparison to \LaTeX{}'s \cs{verb} and \pkg{fancyvrb}'s \cs{Verb} (with \t{breaklines} option from \pkg{fvextra})}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{exampletbl}{*{3}{|F| p{1em}}}
% \c!\lwtttt{...}! &&
% \c!\justtt{...}! &&
% \c!\xurltt{...}! \\\hline
% \lwttt{Use other text with superduperveeerylooong words and words_with_special_characters, e.g. urls: http://example.com/hard-to-break-it-properly. Moreover, look at ``<<'' and ``>>'' symbols, they look different.} &&
% \justtt{Use other text with superduperveeerylooong words and words\_with\_special\_characters, e.g. urls: http://example.com/hard-to-break-it-properly. Moreover, look at ``<<'' and ``>>'' symbols, they look different.} \textit{(needs manual escaping)} &&
% \xurltt{Use other text with superduperveeerylooong words and words_with_special_characters, e.g. urls: http://example.com/hard-to-break-it-properly. Moreover, look at ``<<'' and ``>>'' symbols, they look different.} \\
% \lwttt{\commands, e.g. \LaTeX{}, may produce extra spaces.} &&
% \justtt{\cs{commands}, e.g. \cs{LaTeX}\{\}, may produce extra spaces.} \textit{(needs manual escaping)} &&
% \xurltt{\commands, e.g. \LaTeX{}, may produce extra spaces.} \\\hline
% \c!\lwtverb|...|! &&
% \c!\justverb{...}! &&
% \c!\xurltt|...|! \\\hline
% \lwtverb|\commands, e.g. \LaTeX{}, may produce extra spaces.| &&
% \justverb{\commands, e.g. \LaTeX{}, may produce extra spaces.} &&
% \xurltt|\commands, e.g. \LaTeX{}, may produce extra spaces.|
% \end{exampletbl}
% \caption[]{Comparison to \cs{justtt}, \cs{justverb} and \pkg{xurl}'s
% \cs{url} with the \t{obeyspaces} package option. \emph{Note also that \pkg{hyperref}
% does actually interfere with \pkg{url}, so the result shown above is
% somewhat far from what it should/may be. See \cref{sec:alternatives} for discussion}}
% \label{table:this-justtt-xurltt}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{exampletbl}{*{3}{|F| p{1em}}}
% \c|\lwttt[w,poskrn=0.5em]{...}| &&
% \c|\lwttt[w,negkrn=0.5em]{...}| &&
% \c|\lwttt[w,monospaced]{...}| \\\hline
% \lwttt[w,poskrn=0.5em]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[w,negkrn=0.5em]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[w,monospaced ]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.}
% \end{exampletbl}
% \caption[]{Same text typeset with \thispkg's \cs{lwttt} with interletter spacing adjusted differently}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{exampletbl}{*{3}{|F| p{1em}}}
% \c|\lwttt[w,m,possp=6em]{...}| &&
% \c|\lwttt[w,m,negsp=1em]{...}| &&
% \c|\lwttt[w,monospaced]{...}| \\\hline
% \lwttt[w,m,possp=6em]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[w,m,negsp=1em]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[w,monospaced ]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.}
% \end{exampletbl}
% \caption[]{Same text typeset with \thispkg's \cs{lwttt} with interword spacing adjusted differently}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{exampletbl}{|P{0.15\textwidth}| p{0.5em} |P{0.20\textwidth}| p{0.5em} |P{0.25\textwidth}| p{0.5em} |P{0.30\textwidth}|}
% \lwttt[breaksymr=$\bullet$,breaksyml=$\bullet$]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[breaksymr=$\bullet$,breaksyml=$\bullet$]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[breaksymr=$\bullet$,breaksyml=$\bullet$]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.} &&
% \lwttt[breaksymr=$\bullet$,breaksyml=$\bullet$]{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.}
% \end{exampletbl}
% \caption[]{Same text in columns of different width}
% \end{table}
% \begin{table}[H]
% \centering
% \begin{tabular}{|p{3.2cm}|p{3.2cm}|p{3.2cm}|}
% \c[monospaced]|r1 = x; // A| & \c|r1 = x; // A| & \c[showspaces]|r1 = x; // A| \\
% \c[monospaced]|if (r1 != 0) // B| & \c|if (r1 != 0) // B| & \c[showspaces]|if (r1 != 0) // B| \\
% \c[monospaced]| y = 1; // C| & \c| y = 1; // C| & \c[showspaces]| y = 1; // C|
% \end{tabular}
% \caption[]{This example demonstrates the power of \t{monospaced} option
% (note that \t{A}, \t{B} and \t{C} are properly aligned) and
% compares it with the result of default and \t{showspaces} options.
% The table itself is typeset using fixed-width \c|p{...}| columns.
% The issue with default options originates from different
% space widths used in default and \t{monospaced}-like styles}
% \end{table}
% \section{Usage}\label{sec:usage}
%
% \DescribeMacro{\lwtverb}
% Using {\thispkg} is just as simple as regular \cs{verb}. Here is an example of \cs{lwtverb}:
%
% \begin{examplebox}
% \c!While {\LaTeX} provides \verb+\verb+ allowing us to output things verbatim, e.g. \verb|{\LaTeX}|, {\thispkg} provides \lwtverb+\lwtverb+ allowing the same, e.g. \lwtverb|{\LaTeX}|.!
% \end{examplebox}
%
% \begin{examplebox}
% While {\LaTeX} provides \verb+\verb+ allowing us to output things verbatim, e.g. \verb|{\LaTeX}|, {\thispkg} provides \lwtverb+\lwtverb+ allowing the same, e.g. \lwtverb|{\LaTeX}|.
% \end{examplebox}
%
% \cs{lwtverb} is based on \pkg{fvextra}. It provides two versions of
% \cs{lwtverb} syntax:
%
% \begin{syntax}
% \cs{lwtverb}\oarg{opts}\meta{char}\meta{input}\meta{char}
% \cs{lwtverb}\oarg{opts}\Arg{input}
% \end{syntax}
%
% The latter version should almost always be preferred because it
% much less fragile. It, however, has some limitations, e.g. may fail
% to properly typeset \cs{commands}, cannot have unpaired curly braces
% in argument, may gobble spaces. See \cref{sec:limitations} and \pkg{fvextra}
% manual for more details.
%
% \DescribeMacro{\lwtcode}
% \c!\lwtcode|...|! is just a shorthand for \c!\lwtverb[w]|...|!, i.e.
% it is a version of \cs{lwtverb} defaulted to \t{wrapline} style.
% It may be useful for typesetting inline code sensitive to line breaks.
%
% \DescribeMacro{\lwttt}
% \cs{lwttt} is a limited version of \cs{lwtverb} with syntax of a regular
% command. It may be used in place of \cs{lwtverb} when it is just needed
% to typeset text without any special characters or commands in it.
% \cs{lwttt} may introduce extra space after commands. Note additional
% space after \c|\LaTeX| here: \hbox{\lwttt{{\LaTeX}}}. \cs{lwtverb} handles
% this properly: \hbox{\lwtverb|{\LaTeX}|}.
%
% \DescribeMacro{\justtt}
% \cs{justtt} is like a normal \cs{texttt} but adds shrinking, stretching
% and (proper lexical) hyphenation support by default. Not a verbatim
% command. Doesn't take any options.
%
% \DescribeMacro{\justverb}
% \cs{jusverb} is like a \cs{justtt} but does its best to handle special
% characters. Internally highly relies on \cs{detokenize}. Doesn't take any
% options.
% \section{Options}\label{sec:options}
%
% All \cs{lwtxxx} commands take the same options.
%
% \DescribeMacro{decoration=\meta{cmd1}}
% \DescribeMacro{decoration2=\meta{cmd2}}
% \DescribeMacro{spacebox=\meta{hbox}}
% \t{decoration}, \t{decoration2} and \t{spacebox} options allow altering style
% of individual symbols. The first one takes only a single parameter \meta{cur},
% the current character. \t{cmd2} takes additionally \meta{prev}, the previous
% characher. Consider the example:
%
% \begin{examplebox}
% \c!\lwtverb[decoration=\colorbox{lightgray}, spacebox=\framebox{}]|Text with spaces.|!
% \end{examplebox}
%
% \begin{examplebox}
% \lwtverb[decoration=\colorbox{lightgray}, spacebox=\framebox{}]|Text with spaces.|
% \end{examplebox}
%
% Another example allows different behavior for the first letter of the word.
%
% \begin{examplebox}
% \c!\makeatletter\def\highlight#1#2{\ifx\@sptoken#2\textcolor{red}{#1}\else#1\fi}\makeatother!\\
% \c!\lwtverb[decoration2=\highlight]|Text with spaces.|!
% \end{examplebox}
%
% \begin{examplebox}
% \makeatletter\def\highlight#1#2{\ifx\@sptoken#2\textcolor{red}{#1}\else#1\fi}\makeatother
% \lwtverb[decoration2=\highlight]|Text with spaces.|
% \end{examplebox}
%
%
% \DescribeMacro{gobble=\meta{verbatim, no, extra, all}}
% The \t{gobble} option allows one to alter the behavior
% of {\thispkg} regarding spaces.
%
% The \t{verbatim} option
% value forces {\thispkg} to treat all spaces as normal
% characters except that line breaks near the spaces are
% not marked with \t{breaksymr} and \t{breaksyml}.
%
% The default \t{no} value allows spaces at the beginning
% and at the end of the line to be gobbled. It is the default
% behavior {\LaTeX} itself has. If \t{spacebox} is provided,
% \t{no} behaves exactly as \t{verbatim}.
%
% The \t{extra} value leaves only a single space removing
% all subsequent spaces (may be useful in combination with
% \t{spacebox}).
%
% The \t{all} value removes all spaces completely (even if
% \t{spacebox} is provided).
%
% Here is how one may get all spaces obeyed and highlighted with dots.
%
% \begin{examplebox}
% \c!\lwtcode[spacebox=\hbox to 0.5em {$\hfill\cdot\hfill$}]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{4.5cm}
% \lwtcode[spacebox=\hbox to 0.5em {$\hfill\cdot\hfill$}]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|
% \end{minipage}
% \end{examplebox}
%
% As this behavior is quite common, \t{showspaces} option is a
% shorthand for the desired behavior above.
% Here is how each option affects the outcome.
% \c|<value>| takes the \t{no}, \t{verbatim}, \t{extra}
% and \t{all} value correspondingly.
%
% \begin{examplebox}
% \c!\lwtcode[gobble=<value>]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{6cm}
% \lwtcode[gobble=no]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|
% \end{minipage}
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{6cm}
% \lwtcode[gobble=verbatim]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|
% \end{minipage}
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{6cm}
% \lwtcode[gobble=extra]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|
% \end{minipage}
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{6cm}
% \lwtcode[gobble=all]|Text with a number of words. Spaces: 1[ ], 2[ ], 3[ ], 4[ ], 5[ ]. Note that breaks at spaces are not marked with arrow sign, but_long_words_that_actually_break_somewhere_still_are.|
% \end{minipage}
% \end{examplebox}
%
% Here is how each option behaves on the input consisting almost entirely of spaces:
%
% \begin{examplebox}
% \begin{tabular}{r c}
% \t{no} & ``\lwtcode[gobble=no]| ! |'' \\
% \t{verbatim} & ``\lwtcode[gobble=verbatim]| ! |''\\
% \t{extra} & ``\lwtcode[gobble=extra]| ! |'' \\
% \t{all} & ``\lwtcode[gobble=all]| ! |''
% \end{tabular}
% \end{examplebox}
%
%
% \DescribeMacro{breaksymr=\meta{hbox}}
% \DescribeMacro{breaksyml=\meta{hbox}}
% \t{breaksymr} and \t{breaksyml} allow to specify line break
% indicators, e.g. hyphen, arrow, etc. {\thispkg} effectively
% inserts \c!\discretionary{!\meta{breaksymr}\c!}{!\meta{breaksyml}\c!}{}!
% after each non-space character of the input.
%
% \begin{examplebox}
% \c!\lwtverb[breaksyml=$\triangleleft$, breaksymr=$\triangleright$]|Long_word_that_should_be_hyphenated.|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{3cm}
% \lwtverb[breaksyml=$\triangleleft$, breaksymr=$\triangleright$]|Long_word_that_should_be_hyphenated.|
% \end{minipage}
% \end{examplebox}
%
%
% \DescribeMacro{poskrn=\meta{length}}
% \DescribeMacro{negkrn=\meta{length}}
% Specifies interletter stretching (\t{poskrn}) and shrinking (\t{negkrn}) boundaries.
%
% \begin{examplebox}
% \c!\lwtverb[poskrn=1em, negkrn=0.3em]|This_text_must_be_very_loose <filler_text_that_should_wrap>|!\\
% \c!\lwtverb[poskrn=1em, negkrn=0.3em]|This_text_must_be_very_tight <another_filler>|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{7cm}
% \lwtverb[poskrn=1em, negkrn=0.3em]|This_text_must_be_very_loose <filler_text_that_should_wrap>|\\
% \lwtverb[poskrn=1em, negkrn=0.3em]|This_text_must_be_very_tight <another_filler>|
% \end{minipage}
% \end{examplebox}
%
%
% \DescribeMacro{possp=\meta{length}}
% \DescribeMacro{negsp=\meta{length}}
% Specifies interword stretching (\t{possp}) and shrinking (\t{negsp}) boundaries.
%
% \begin{examplebox}
% \c!\lwtverb[possp=1em, negsp=0.3em]|Spaces here must be very wide <filler_text_that_should_wrap>|!\\
% \c!\lwtverb[possp=1em, negsp=0.3em]|Spaces here must be very short <another_filler>|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{7.4cm}
% \lwtverb[possp=1em, negsp=0.4em]|Spaces here must be reasonably wide <filler_text_that_should_wrap>|\\
% \lwtverb[possp=1em, negsp=0.4em]|Spaces here must be very short <another_filler>|
% \end{minipage}
% \end{examplebox}
%
%
% \DescribeMacro{spwidth=\meta{length}}
% \DescribeMacro{hardspwidth=\meta{length}}
% Specifies interword space width in normal and verbatim \t{gobble} mode.
%
%
% \DescribeMacro{breakhandler=\meta{cmd3}}
% Specifies a command with a three parameters, namely \meta{cur},
% \meta{prev}, \meta{discretionary}, i.e. current char, previous char
% and discretionary box. One should return \meta{discretionary} in
% order to allow break and nothing to prevent it. E.g. here is how
% \t{keepwords}-like behavior may be achieved.
%
% \begin{examplebox}
% \c!\def\ignorethree#1#2#3{}!\\
% \c!\lwtverb[breakhandler=\ignorethree]|Will not be able to break words. Long-word-that-is-to-be-normally-hyphenated will be left as is.|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{5cm}
% \def\ignorethree#1#2#3{\relax}
% \lwtverb[breakhandler=\ignorethree]|Will not be able to break words. Long-word-that-is-to-be-normally-hyphenated will be left as is.|
% \end{minipage}
% \end{examplebox}
%
% One may imagine a requirement to break only at a certain symbol,
% e.g. hyphen. Here is how it may be achieved.
%
% \begin{examplebox}
% \c!\def\breakhyph#1#2#3{\if-#2#3\fi}!\\
% \c!\lwtverb[breakhandler=\breakhyph]|Will not be able to break words. Long-word-that-is-to-be-normally-hyphenated will break at ``-''.|!
% \end{examplebox}
%
% \begin{examplebox}
% \begin{minipage}{5cm}
% \def\breakhyph#1#2#3{\if-#2#3\fi}
% \lwtverb[breakhandler=\breakhyph]|Will not be able to break words. Long-word-that-is-to-be-normally-hyphenated will break at ``-''.|
% \end{minipage}
% \end{examplebox}
%
% Here we test if the previous character was a hyphen and if so
% insert discretionary.
%
%
% \DescribeMacro{debug}
% Synonym of \c!decoration=\colorbox{lightgray}!.
%
% \DescribeMacro{breakline, b}
% Synonym of \c!breaksymr={}, breaksyml={}!.
%
% \DescribeMacro{wrapline, w}
% Synonym of \c!breaksymr=<hookedarrow>, breaksyml={}!.
%
% \DescribeMacro{hyphenate, h}
% Synonym of \c!breaksymr={-}, breaksyml={}!.
%
% \DescribeMacro{monospaced, m}
% All spacings are non-adjustable, all spaces are as in verbatim mode.
%
% \DescribeMacro{showspaces}
% Installs \t{spacebox} with a small central dot.
%
% \DescribeMacro{obeyspaces}
% Synonym of \c!gobble=verbatim!.
%
% \DescribeMacro{nospaces}
% Synonym of \c!gobble=all!.
% \section{Comparison to other approaches}\label{sec:alternatives}
% There are plenty of packages and/or tecniques that provide
% similar functionality. Why then {\thispkg}? Here is a brief
% overview of alternatives to {\thispkg} that reveals some
% subtleties of each of them.
%
% \begin{description}[style=nextline]
% \item[\cs{tt}, \cs{texttt}] Requires manual escaping of
% special characters. Does not support hyphenation by
% default.
% \item[\cs{justtt}] Simple extension of the previous approach.
% See \href{https://tex.stackexchange.com/a/799/203829}{%
% this StackExchange answer} for details. \cs{detokenize}
% handles most of the special characters automatically,
% but fails with commands, e.g. \c|\detokenize{\LaTeX{}}|
% introduces unwanted extra space after the command name:
% \texttt{\detokenize{\LaTeX{}}}. \cs{detokenize} also fails to
% preserve \c|<<| and \c|>>| resulting in \texttt{\detokenize{<<}}
% and \texttt{\detokenize{>>}} correspondingly. {\thispkg} provides
% \cs{justtt} (without \cs{detokenize}) and \cs{justverb}
% (\cs{detokenize}-based) just for completeness.
% \item[{\LaTeX}'s \cs{verb}] Does not allow line breaks inside
% words. May cause overfull hboxes. Very fragile.
% \item[\pkg{fancyvrb}'s \cs{Verb}] With the help of \pkg{fvextra}
% supports line breaks anywhere in the string and can indicate
% breaks appropriately. Not justifiable~--- produces too
% ragged result. Without \t{breakanywhere} option may cause overfull
% hboxes with long enough words. See examples above. \pkg{fancyvrb}
% and \pkg{fvextra} provide \cs{SaveVerb}, \cs{UseVerb} and many
% more useful commands to cope with plain \cs{Verb} limitations.
% {\thispkg} does not provide such mechanism.
% \item[\pkg{minted}'s \cs{mintinline}] Does not allow line breaks
% in inline code at all.
% \item[\pkg{url}'s or \pkg{xurl}'s \cs{url}] Does its job well but
% handles some characters inconsistently (e.g. \c|<<| is typeset
% in typewriter font, but \c|>>| is not). Suffers from the same
% problems as \cs{detokenize} does. \pkg{hyperref} may interfere
% with \pkg{url}. Actually, it can be seen on \cref{table:this-justtt-xurltt}.
% \cs{xurltt} from the example above is defined as follows:
% \c|\DeclareUrlCommand\xurltt{\urlstyle{tt}}|.
% \end{description}
% \section{Limitations}\label{sec:limitations}
% There are many limitations the author is currently aware of:
%
% \begin{itemize}
% \item Missing support for inline math.
% \item Hyphenation does not take into accout whether
% it is semantically allowed to break at certain position.
% True hyphenation is desirable for typesetting text but
% in such case simple \cs{justtt}-based approach would
% be enough.
% \item Only some of the command options have their package
% option equivalents. The user may, however, simply define
% his own command as {\thispkg} does with \cs{lwtcode}.
% \item There is no option to trim leading and trailing spaces.
% But is such an option really necessary?
% \item As with all other inline verbatim commands, \cs{lwtverb}
% and others are fragile. It means that \cs{lwtverb} (but not
% \cs{lwttt}) cannot be used in section names, captions, it may
% conflict with some tabular environments. \pkg{fvextra} fixes
% a lot of \pkg{fancyvrb}'s \cs{Verb} fragility issues, but not all
% and at some cost (whitespace preservation, alternative syntax
% with its own limitations, etc.). {\thispkg} tries to follow
% \pkg{fvextra} implementation in order to provide robust
% variant of \cs{lwtverb}.
% \item \c!\lwtverb|...|! may exibit a bit strange behavior when
% passed as an argument to other commands (e.g. \c!\id{\lwtverb|{\LaTeX }|}!
% actually becomes ``{\def\id#1{#1}\id{\lwtverb|{\LaTeX }|}}'' instead of
% desired ``\lwtverb|{\LaTeX }|'', where \cs{id} is defined
% as follows: \c|\def\id#1{#1}|. \c!\lwtverb{...}! survives
% and produces almost desired output
% ``{\def\id#1{#1}\id{\lwtverb{{\LaTeX }}}}'' but fails to preserve
% spaces after \c!\LaTeX!.
% \end{itemize}
% \section{Historical notes}\label{sec:notes}
%
% The package was originally implemented on top of
% \pkg{newverbs}. It provides very simple and
% straightforward approach to verbatim commands~---
% one just needs to feed his command to \cs{Collectverb}
% which just passes collected input as an argument
% to provided command. It, however, is as fragile
% as \cs{verb} is, so it is hardly acceptible.
%
% Implementation on top of plain \pkg{fancyvrb}
% was much less fragile, but it still was far from
% what it might be.
%
% Current \pkg{fvextra}-based approach finally won
% and was adopted here.
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
% \subsection{Interaction with other packages}
%
% Suppress \pkg{hyperref} warnings if {\thispkg} is used in titles
% \begin{macrocode}
\AtBeginDocument{
\@ifpackageloaded{hyperref}%
{
\pdfstringdefDisableCommands{
\def\lwtverb{}
\def\lwtcode{}
\def\lwttt{}
\def\justtt{}
\def\justverb{}
}
}{}
}
% \end{macrocode}
% \subsection{Package Options}
%
% Additional stretching to be added after each non-space char
% \begin{macrocode}
\DeclareOptionX{poskrn}{%
\DeclareDocumentCommand\@lwtverb@poskrn{}{#1}}
% \end{macrocode}
% Additional shrinking to be added after each non-space char
% \begin{macrocode}
\DeclareOptionX{negkrn}{%
\DeclareDocumentCommand\@lwtverb@negkrn{}{#1}}
% \end{macrocode}
% Additional stretching to be added after each space char
% \begin{macrocode}
\DeclareOptionX{possp}{%
\DeclareDocumentCommand\@lwtverb@possp{}{#1}}
% \end{macrocode}
% Additional shrinking to be added after each space char
% \begin{macrocode}
\DeclareOptionX{negsp}{%
\DeclareDocumentCommand\@lwtverb@negsp{}{#1}}
% \end{macrocode}
% Width of a regular space
% \begin{macrocode}
\DeclareOptionX{spwidth}{%
\DeclareDocumentCommand\@lwtverb@spwidth{}{#1}}
% \end{macrocode}
% Width of space in verbatim mode
% \begin{macrocode}
\DeclareOptionX{hardspwidth}{%
\DeclareDocumentCommand\@lwtverb@hardspwidth{}{#1}}
% \end{macrocode}
% Handle unknown options
% \begin{macrocode}
\DeclareOptionX*{%
\PackageWarning{lwtverb}{`\CurrentOption' ignored}}
% \end{macrocode}
% Some reasonable defaults
% \begin{macrocode}
\ExecuteOptionsX{
poskrn=0.3pt, % higher values result in 'a b c d' (too loose)
negkrn=0.3pt, % higher values result in 'abcd' (too tight)
possp=0.3em, % higher values result in 'abcd efgh'
negsp=0.1em, % higher values result in 'abcdefgh'
spwidth=0.4em,
hardspwidth=0.5em,
}
% \end{macrocode}
% Done with package options
% \begin{macrocode}
\ProcessOptionsX\relax
% \end{macrocode}
% \subsection{Command Options}
%
% \begin{macrocode}
\long\def\@firstoffour#1#2#3#4{#1}
\long\def\@fourthoffour#1#2#3#4{#4}
\options{
/lwtverb/.new family,
% options
/lwtverb/decoration/.new value = \relax,
/lwtverb/decoration2/.new value = \relax,
/lwtverb/spacebox/.new value = \relax,
/lwtverb/breaksymr/.new value = {},
/lwtverb/breaksyml/.new value = {},
/lwtverb/poskrn/.new value = \@lwtverb@poskrn,
/lwtverb/negkrn/.new value = \@lwtverb@negkrn,
/lwtverb/possp/.new value = \@lwtverb@possp,
/lwtverb/negsp/.new value = \@lwtverb@negsp,
/lwtverb/spwidth/.new value = \@lwtverb@spwidth,
/lwtverb/hardspwidth/.new value = \@lwtverb@hardspwidth,
/lwtverb/gobble/.new choice = { verbatim, no, extra, all },
/lwtverb/gobble = no,
/lwtverb/breakhandler/.new value = \@fourthoffour\relax,
% styles
/lwtverb/debug/.new style* = {
/lwtverb/decoration = \colorbox{lightgray},
},
/lwtverb/breakline/.new style* = {
/lwtverb/breaksymr = {},
/lwtverb/breaksyml = {},
},
/lwtverb/wrapline/.new style* = {
/lwtverb/h,
/lwtverb/breaksymr = {},
/lwtverb/breaksyml = {%
\makebox[1em]{%
\tiny$\hookrightarrow$}%
},
},
/lwtverb/hyphenate/.new style* = {
/lwtverb/breaksymr = {-},
/lwtverb/breaksyml = {},
},
/lwtverb/monospaced/.new style* = {
/lwtverb/poskrn = 0pt,
/lwtverb/negkrn = 0pt,
/lwtverb/possp = 0pt,
/lwtverb/negsp = 0pt,
/lwtverb/spwidth = \@lwtverb@hardspwidth,
},
/lwtverb/showspaces/.new style* = {
/lwtverb/spacebox=\hbox to \@lwtverb@hardspwidth {%
\textcolor{gray}{$\hfill\cdot\hfill$}},
},
/lwtverb/obeyspaces/.new style* = {
/lwtverb/gobble=verbatim,
},
/lwtverb/nospaces/.new style* = {
/lwtverb/gobble=all,
},
/lwtverb/keepwords/.new style* = {
/lwtverb/breakhandler = \@firstoffour\relax,
},
% shorthands
/lwtverb/b/.new style* = { /lwtverb/breakline },
/lwtverb/w/.new style* = { /lwtverb/wrapline },
/lwtverb/h/.new style* = { /lwtverb/hyphenate },
/lwtverb/m/.new style* = { /lwtverb/monospaced }
}
% \end{macrocode}
% \subsection{Character Decorator}
%
% \begin{macro}{\@lwtverb@makespace}
% Creates properly-sized \cs{hspace} from (implicitly
% passed) options. This space replaces the actual space
% character of the input string.
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@makespace{}{%
% \end{macrocode}
% Allow {\LaTeX} to remove spaces automatically at the
% beginning and at the end of the line; use unstarred
% \cs{hspace} version for this purpose.
% \begin{macrocode}
\hspace{\option{/lwtverb/spwidth}%
plus \option{/lwtverb/possp}%
minus \option{/lwtverb/negsp}}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@makehardspace}
% Creates properly-sized \cs{hspace} from (implicitly
% passed) options. This space replaces the actual space
% character of the input string and cannot be gobbled.
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@makehardspace{}{%
% \end{macrocode}
% Prevent {\LaTeX} from removing spaces automatically at the
% beginning and at the end of the line; use starred
% \cs{hspace} version for this purpose.
% \begin{macrocode}
\hspace*{\option{/lwtverb/hardspwidth}%
plus \option{/lwtverb/possp}%
minus \option{/lwtverb/negsp}}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@makekern}
% Creates properly-sized \cs{hspace} from (implicitly
% passed) options. This space is put between letters in
% words to make them shirnkable and stretchable enough.
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@makekern{}{%
% \end{macrocode}
% Allow LaTeX to remove spaces automatically at the
% beginning and at the end of the line; use unstarred
% \cs{hspace} version for this purpose
% \begin{macrocode}
\hspace*{0pt%
plus \option{/lwtverb/poskrn}%
minus \option{/lwtverb/negkrn}}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@makespacekern}
% Creates properly-sized \cs{hspace} from (implicitly
% passed) options. This space is put between letter and
% decorated space to make them shirnkable and stretchable.
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@makespacekern{}{%
% \end{macrocode}
% Use starred (non-breakable) version of \cs{hspace}
% to allow the following discretionary to do its job.
% \begin{macrocode}
\hspace{0pt%
plus \option{/lwtverb/poskrn}%
minus \option{/lwtverb/negkrn}}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@makediscretionary}
% Creates discrtetionary from (implicitly passed) options
% that is used to indicate line break.
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@makediscretionary{}{%
\discretionary{%
\hbox{\option{/lwtverb/breaksymr}}%
}{%
\hbox{\option{/lwtverb/breaksyml}}%
}{}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@decoratedspace}
% Creates a box to be used in place of the actual
% space character of the input. Unlike \cs{@lwtverb@makespace},
% takes \t{spacebox} option into account.
% \begin{arguments}
% \item The space character (ignored)
% \item The previous character
% \end{arguments}
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@decoratedspace{m m}{%
\ifoptionvoid{/lwtverb/spacebox}{%
\ifnum\option{/lwtverb/gobble/@ord}=0% verbatim
% \end{macrocode}
% Forbid break at first char as it may cause extra break
% in some rare cases (e.g. in \c|p{}| tabular cells).
% \begin{macrocode}
\ifx\relax#2%
\else%
\allowbreak%
\fi%
\@lwtverb@makehardspace%
\else%
\@lwtverb@makespace%
\fi%
}{%
% \end{macrocode}
% Same trick here leads to the problem solved above... so
% leave it as is.
% \begin{macrocode}
\@lwtverb@makespacekern%
\allowbreak%
\option{/lwtverb/spacebox}%
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@decoratednonspace}
% Creates a box to be used in place of the actual
% non-space character of the input. Takes
% \t{decoration} option into account and does not
% apply any interletter spacing.
% \begin{arguments}
% \item The non-space character
% \end{arguments}
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@decoratednonspace{m m}{%
\ifoptionvoid{/lwtverb/decoration2}{%
\option{/lwtverb/decoration}{#1}%
}{%
\option{/lwtverb/decoration2}{#1}{#2}%
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lwtverb@breakablechar}
% This macro actually does the job of inserting the
% interletter glue, interword spacing and potential line
% breaks. Almost all options passed to \cs{lwtverb} and
% other commands of {\thispkg} are handled here.
% \begin{arguments}
% \item Current character to be typeset and decorated
% \item Previous characher (\cs{relax} for the first)
% \end{arguments}
% The previous character is used to detect word boundaries
% in order not to insert discretionary right before the
% space. The motivation for this is simple~--- otherwise
% hyphen (or in general a pair of any two symbols) may be
% inserted right before the space which is certainly
% unpleasant in most cases.
% \begin{macrocode}
\DeclareDocumentCommand\@lwtverb@breakablechar{m m}{%
% \end{macrocode}
% Handle spaces separately. If there is a \t{spacebox} option
% set, we treat space as a regular character except we should
% not insert hyphenation marks.
% \begin{macrocode}
\ifx\@sptoken#1%
\ifcase\option{/lwtverb/gobble/@ord}%
% verbatim
\@lwtverb@decoratedspace{#1}{#2}%
\or% no
\@lwtverb@decoratedspace{#1}{#2}%
\or% extra
\ifx\@sptoken#2%
\else%
\@lwtverb@decoratedspace{#1}{#2}%