summaryrefslogtreecommitdiff
path: root/support/match_parens/match_parens.1
blob: 21f811337858bd455a3397e8912ce7da667e8f50 (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
.TH match_parens 1 "March 23, 2023" "match_parens version 1.44" "DekDoc scripts"
.SH NAME

match_parens - find mismatches of various brackets and quotes

.SH Synopsis

.B match_parens [filename]

.SS Options

.B -h
.RS
print this help and exit
.RE
.B -H,--help
.RS
print full documentation and exit
.RE
.B -V,--version
.RS
print version and exit
.RE
.B -l,--latex
.RS
convert ``...'' to “...” before testing
.RE
.B -n,--number=N
.RS
set number of mismatching characters shown to N (default: 10)
.RE
.B -p,--pairs=S
.RS
set matching pairs to S (default: {}[]()""“”''‘’)
.RE
.B    --test
.RS
do an internal test and exit
.RE

.SH Description
Mismatches of parentheses, braces, (angle) brackets, especially in TeX sources which may be rich in those, may be difficult to trace. This little script helps you by writing your text to standard output, after adding a left margin to your text, which will normally be almost empty, but will clearly show up to 10 mismatches. (Just try me on myself to see that the parenthesis starting this sentence will not appear to be matched at the end of the file. If you look at me in the vim editor, then select this paragraph and try the command: :!%. 

By default, the following pairs are tested: 

.B ()
.RS
round brackets or parentheses
.RE
.B {}
.RS
curly brackets or braces
.RE
.B []
.RS
square brackets
.RE
.B <>
.RS
angle brackets (within html text only)
.RE
.B ""
.RS
ASCII double quotes
.RE
.B “”
.RS
Unicode double quotation marks
.RE
.B ''
.RS
ASCII single quotes
.RE
.B ‘’
.RS
Unicode single quotation marks
.RE

The exit value of the script is 0 when there are no mismatches, 1 otherwise. 

Angle brackets are only looked for inside HTML text, where HTML is supposed to start with <html> or =begin␣rdoc and to end with </html> or =end. 

.SH Options

.B -h,--help
.RS
print short help information and exit.
.RE
.B -H,--Help
.RS
print full documentation via less and exit.
.RE
.B -V,--version
.RS
print this script's version and exit.
.RE
.B -l,--latex
.RS
convert ``...'' to “...” before testing.
.RE
.B -n,--number=N
.RS
Set number of mismatching characters shown to N. By default, only the first 10 are shown.
.RE
.B -p,--pairs=S
.RS
Set matching pairs to S (default: {}[]()""“”''‘’). For example, if you want to look for mismatching ASCII single quotes \fIonly\fR, use --pairs="''". Or, if you want to match braces and guillemets only, use -p␣«». Note that if html is detected in your text, <> is automatically added to the pairs list. So by default, <...> is tested only in html, but you can test that in other text by specifying the <> pair in the --pairs option.
.RE
.B    --test
.RS
do an internal test and exit. Note that if, with the --pairs option, you specify an other pairs list than the default, the test will probably fail, but you can still see the effects of your pairs list on the test data.
.RE

.SH Examples
Suppose we have two files, good and bad, containing these texts: 

.B good:
.RS
This is a (simple) test without mismatches
.RE

.B bad:
.RS
This is a (simple test containing mismatches
.RE

then here are some usage examples. First a simple test on these files:    $ matchparens good
         1 || This is a (simple) test
         2 || without mismatches
   $ echo $?
   0
   $ matchparens bad
         1 | (| This is a (simple test
         2 | (| containing mismatches
   $ echo $?
   1

Just report if there are mismatches:     $ matchparens good >/dev/null && echo fine || echo problems
   fine
   $ matchparens bad >/dev/null && echo fine || echo problems
   problems

Report all tex files with mismatches in the current directory:    $ for i in *.tex; do matchparens $i >/dev/null || echo $i; done

Matches must be in correct order:    $ echo -e "This is a ([simple)] test\n" | match_parens
         1 ([)]This is a ([simple)] test
         2 ([)]

.SH Author
Wybo Dekker (wybo@dekkerdocumenten.nl) 

.SH Copyright
Released under the GNU General Public License (www.gnu.org\fIcopyleft\fRgpl.html)