-
Notifications
You must be signed in to change notification settings - Fork 794
Tools: Simple Bikeshed to LaTeX search and replace #7994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/sh | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: $0 <LaTeX source> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we use curly braces for all variable references, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Greedy application of \\libconcept and \\exposconcept macros to anything that | ||
looks like a concept. | ||
EOF | ||
} | ||
|
||
case "$1" in | ||
-h|--help|"") | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
|
||
source_dir="${0%/*}/../source" | ||
|
||
concepts=$(grep -oh 'deflibconcept{[a-z_:]*}' "$source_dir"/*.tex \ | ||
| sed -e 's/^deflibconcept{\(.*\)}$/\1/' \ | ||
| sed -e ':a; N; $!ba; s/\n/\\|/g' | ||
) | ||
|
||
exposconcepts=$(grep -oh 'defexposconceptn\?c\?{[a-z-]*}' "$source_dir"/*.tex \ | ||
| sed -e 's/^defexposconceptn\?c\?{\(.*\)}$/\1/' \ | ||
| sed -e ':a; N; $!ba; s/\n/\\|/g' | ||
) | ||
|
||
sed -e 's,\([^\\{.-]\)\<\('"$concepts"'\)\>\([^-]\),\1@\\libconcept{\2}@\3,g' \ | ||
-e 's,\([^\\{.-]\)\<\('"$exposconcepts"'\)\>\([^-]\),\1@\\exposconcept{\2}@\3,g' \ | ||
-e 's,\\exposid\(nc\)\?{\('"$concepts"'\)},\\libconcept{\2},g' \ | ||
-e 's,\\exposid\(nc\)\?{\('"$exposconcepts"'\)},\\exposconcept\1{\2},g' \ | ||
-e 's,\<\(The\|the\|or\|valid\|supplied\) @\\libconcept{range}@,\1 range,g' \ | ||
-e 's,\<\(The\|the\|following\|equivalence\) @\\libconcept{relation}@,\1 relation,g' \ | ||
-e 's,\<\(The\|the\|calling\) @\\libconcept{regular}@,\1 regular,g' \ | ||
-e 's,\<\(trivially\) @\\libconcept{copyable}@,\1 copyable,g' \ | ||
-e 's,@\\libconcept{integral}@ \(promotion\|value\|of\|constant\|constants\|type\|types\)\>,integral \1,g' \ | ||
-e 's,@\\libconcept{view}@ \(the\|of\)\>,view \1,g' \ | ||
"$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/zsh | ||
|
||
|
||
itemize=0 | ||
empty=0 | ||
|
||
sed -e 's,<pre>,\\begin{itemdecl},g' \ | ||
-e 's,</pre>,\\end{itemdecl},g' \ | ||
-e 's,</\?blockquote>,,g' \ | ||
-e 's,</\?code>,`,g' \ | ||
-e 's,// exposition only,// \\expos,g' \ | ||
-e 's,<i>implementation-defined</i>,@\\impdefx{TODO}@,g' \ | ||
-e 's,<i>see below</i>,@\\seebelow@,g' \ | ||
-e 's,concept <i>\([a-z]\+-[a-z-]\+\)</i>,concept @\\defexposconcept{\1}@,g' \ | ||
-e 's,<i>\([a-z]\+-[a-z-]\+\)</i>,@\\exposid{\1}@,g' \ | ||
-e 's,<i>Constraints</i>:,\\pnum\n\\constraints,g' \ | ||
-e 's,<i>Effects</i>:,\\pnum\n\\effects,g' \ | ||
-e 's,<i>Mandates</i>:,\\pnum\n\\mandates,g' \ | ||
-e 's,<i>Preconditions</i>:,\\pnum\n\\expects,g' \ | ||
-e 's,<i>Remarks</i>:,\\pnum\n\\remarks,g' \ | ||
-e 's,<i>Returns</i>:,\\pnum\n\\returns,g' \ | ||
-e 's,<i>Throws</i>:,\\pnum\n\\throws,g' \ | ||
-e 's,</\?i>,,g' \ | ||
-e 's,<,<,g' \ | ||
-e 's,`i`<sup>th</sup>,#iiiiiiiiith#,g' \ | ||
-e 's,`i`,i,g' \ | ||
-e 's,// \[\([.a-z]\+\)],// \\ref{\1},g' \ | ||
-e 's, *(\[\([.a-z]\+\)]),\\iref{\1},g' \ | ||
-e 's,\<i\>,$i$,g' \ | ||
-e 's,#iiiiiiiiith#,$i^\\text{th}$,g' \ | ||
-e 's,`\[\([^\,]\+\)\, *\([^`]\+\))`,\\range{\1}{\2},' \ | ||
-e 's,`\[\([^\,]\+\)\, *\([^`]\+\)]`,\\crange{\1}{\2},' \ | ||
-e 's,`\([^`]\+\)`,\\tcode{\1},g' \ | ||
$1 | while IFS='' read -r line; do | ||
if [[ "$line" =~ '^- ' ]]; then | ||
if ((!itemize)); then | ||
itemize=1 | ||
echo -E '\begin{itemize}' | ||
fi | ||
echo -E "\item${line#-}" | ||
continue | ||
elif ((itemize)); then | ||
echo -E '\end{itemize}' | ||
itemize=0 | ||
elif [[ -z "$line" ]]; then | ||
((empty)) && continue | ||
empty=1 | ||
elif ((empty)); then | ||
empty=0 | ||
fi | ||
echo -E "$line" | ||
done |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script needs bash; plain "sh" is not enough, because it uses
x=$(blah)
syntax.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I was using
dash
, hoping it is close enough to plainsh
. But it seems only backticks would be supported. Fine.bash
is everywhere we care about.