Skip to content

Commit 38761b3

Browse files
committed
Tools: Simple Bikeshed to LaTeX search and replace
* bs_to_tex.sh does a first pass on the wording sources of a Bikeshed paper. * add_libconcept.sh can be used as a second pass to index concept names.
1 parent ac78ae7 commit 38761b3

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

tools/add_libconcept.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
usage() {
4+
cat <<EOF
5+
Usage: $0 <LaTeX source>
6+
7+
Greedy application of \\libconcept and \\exposconcept macros to anything that
8+
looks like a concept.
9+
EOF
10+
}
11+
12+
case "$1" in
13+
-h|--help|"")
14+
usage
15+
exit 1
16+
;;
17+
esac
18+
19+
source_dir="${0%/*}/../source"
20+
21+
concepts=$(grep -oh 'deflibconcept{[a-z_:]*}' "$source_dir"/*.tex \
22+
| sed -e 's/^deflibconcept{\(.*\)}$/\1/' \
23+
| sed -e ':a; N; $!ba; s/\n/\\|/g'
24+
)
25+
26+
exposconcepts=$(grep -oh 'defexposconceptn\?c\?{[a-z-]*}' "$source_dir"/*.tex \
27+
| sed -e 's/^defexposconceptn\?c\?{\(.*\)}$/\1/' \
28+
| sed -e ':a; N; $!ba; s/\n/\\|/g'
29+
)
30+
31+
sed -e 's,\([^\\{.-]\)\<\('"$concepts"'\)\>\([^-]\),\1@\\libconcept{\2}@\3,g' \
32+
-e 's,\([^\\{.-]\)\<\('"$exposconcepts"'\)\>\([^-]\),\1@\\exposconcept{\2}@\3,g' \
33+
-e 's,\\exposid\(nc\)\?{\('"$concepts"'\)},\\libconcept{\2},g' \
34+
-e 's,\\exposid\(nc\)\?{\('"$exposconcepts"'\)},\\exposconcept\1{\2},g' \
35+
-e 's,\<\(The\|the\|or\|valid\|supplied\) @\\libconcept{range}@,\1 range,g' \
36+
-e 's,\<\(The\|the\|following\|equivalence\) @\\libconcept{relation}@,\1 relation,g' \
37+
-e 's,\<\(The\|the\|calling\) @\\libconcept{regular}@,\1 regular,g' \
38+
-e 's,\<\(trivially\) @\\libconcept{copyable}@,\1 copyable,g' \
39+
-e 's,@\\libconcept{integral}@ \(promotion\|value\|of\|constant\|constants\|type\|types\)\>,integral \1,g' \
40+
-e 's,@\\libconcept{view}@ \(the\|of\)\>,view \1,g' \
41+
"$@"

tools/bs_to_tex.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/zsh
2+
3+
itemize=0
4+
empty=0
5+
6+
sed -e 's,<pre>,\\begin{itemdecl},g' \
7+
-e 's,</pre>,\\end{itemdecl},g' \
8+
-e 's,</\?blockquote>,,g' \
9+
-e 's,</\?code>,`,g' \
10+
-e 's,// exposition only,// \\expos,g' \
11+
-e 's,<i>implementation-defined</i>,@\\impdefx{TODO}@,g' \
12+
-e 's,<i>see below</i>,@\\seebelow@,g' \
13+
-e 's,concept <i>\([a-z]\+-[a-z-]\+\)</i>,concept @\\defexposconcept{\1}@,g' \
14+
-e 's,<i>\([a-z]\+-[a-z-]\+\)</i>,@\\exposid{\1}@,g' \
15+
-e 's,<i>Constraints</i>:,\\pnum\n\\constraints,g' \
16+
-e 's,<i>Effects</i>:,\\pnum\n\\effects,g' \
17+
-e 's,<i>Mandates</i>:,\\pnum\n\\mandates,g' \
18+
-e 's,<i>Preconditions</i>:,\\pnum\n\\expects,g' \
19+
-e 's,<i>Remarks</i>:,\\pnum\n\\remarks,g' \
20+
-e 's,<i>Returns</i>:,\\pnum\n\\returns,g' \
21+
-e 's,<i>Throws</i>:,\\pnum\n\\throws,g' \
22+
-e 's,</\?i>,,g' \
23+
-e 's,&lt;,<,g' \
24+
-e 's,`i`<sup>th</sup>,#iiiiiiiiith#,g' \
25+
-e 's,`i`,i,g' \
26+
-e 's,// \[\([.a-z]\+\)],// \\ref{\1},g' \
27+
-e 's,(\[\([.a-z]\+\)]),\\iref{\1},g' \
28+
-e 's,\<i\>,$i$,g' \
29+
-e 's,#iiiiiiiiith#,$i^\\text{th}$,g' \
30+
-e 's,`\[\([^\,]\+\)\, *\([^`]\+\))`,\\range{\1}{\2},' \
31+
-e 's,`\[\([^\,]\+\)\, *\([^`]\+\)]`,\\crange{\1}{\2},' \
32+
-e 's,`\([^`]\+\)`,\\tcode{\1},g' \
33+
$1 | while IFS='' read -r line; do
34+
if [[ "$line" =~ '^- ' ]]; then
35+
if ((!itemize)); then
36+
itemize=1
37+
echo -E '\begin{itemize}'
38+
fi
39+
echo -E "\item${line#-}"
40+
continue
41+
elif ((itemize)); then
42+
echo -E '\end{itemize}'
43+
itemize=0
44+
elif [[ -z "$line" ]]; then
45+
((empty)) && continue
46+
empty=1
47+
elif ((empty)); then
48+
empty=0
49+
fi
50+
echo -E "$line"
51+
done

0 commit comments

Comments
 (0)