.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 or =begin␣rdoc and to end with 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)