[texhax] boldfacing words from a list
Tom Schneider
toms at ncifcrf.gov
Thu Sep 28 23:50:04 CEST 2006
Chris:
> My hope was to be able to bold them somewhat automatically, only having
> to type any markup commands once.
Make a program!
> Thus, typing \vocabulary{profits} every time that word appears in the
> source is no easier than typing \textbf{profits} every time it appears.
> In fact, the former is more keystrokes.
Make a program!
Here's a csh or tcsh script that will do it. It is not smart enough
(nor am I in this horrid language) to deal with words at ends of lines
- just add a space and a '%' to protect it.
#!/bin/tcsh -f
#(ie run the tshell on this but don't read the .cshrc or .tcshrc)
echo version = 1.00 of boldit 2006 Sep 28
# 2006 Sep 28, 1.00: origin
if ($#argv < 2) then
echo 'usage: boldit [latex.tex file] [word list]
echo 'Put a LaTeX bold command on every word listed in the file.'
exit
endif
# define the arguments:
set latex = $1
set wordlist = $2
set name = "\\textbf"
set tmp = /tmp/`whoami`.boldit
cp $latex $tmp
# step through the wordlist and change each word
foreach word (`cat $wordlist`)
echo "changing $word"
cat $tmp |\
# convert words surrounded by spaces: \
sed "s/ $word / $name{$word} /g" |\
# convert words at beginning of line, followed by a space: \
sed "s/^$word /\\textbf{$word} /g" |\
# convert words at ending of line, preceeded by a space: \
# sed "s/ $word\\$/\\textbf{$word} /g" |\ this doesn't work \
# sed "s/ $word$/\\textbf{$word} /g" |\ this doesn't work \
# sed "s/ $word\$/\\textbf{$word} /g" |\ this doesn't work \
cat > $latex
cp $latex $tmp
end
echo ----
Save the text, give permissions to execute (with chmod).
If you have a Mac (OSX) you can do this easily with the Terminal. On
a Windows you're on your own but cygwin probably can run the script.
Tom
Dr. Thomas D. Schneider
National Institutes of Health
National Cancer Institute
Center for Cancer Research Nanobiology Program
Molecular Information Theory Group
Frederick, Maryland 21702-1201
toms at ncifcrf.gov
permanent email: toms at alum.mit.edu (use only if first address fails)
http://www.ccrnp.ncifcrf.gov/~toms/
More information about the texhax
mailing list