Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tools/add_libconcept.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

usage() {
cat <<EOF
Usage: $0 <LaTeX source>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use curly braces for all variable references, e.g. ${0}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${0} specifically reads very strange to me and unconditional use of braces is inconsistent with the rest of our shell scripts. I very much prefer to only use braces when they serve a purpose.


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' \
"$@"
51 changes: 51 additions & 0 deletions tools/bs_to_tex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

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,&lt;,<,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