Eom clean up.txt
From Encyclopedia of Mathematics
Revision as of 13:49, 20 June 2014 by Thomas Unger (talk | contribs) (created file eom_clean_up.txt)
--AppleScript
(*
This script can be used in conjunction with TeXShop to clean up EOM source files.
It replaces "<img ..." strings by $•$ and "<table class="eq" ..." strings by $$•$$.
It also cleans up the list of references.
After execution, the cursor is positioned at the first bullet •.
To go to the next bullet, press CTRL-COMMAND-F in TeXShop;
to go to the previous bullet (if it has not been replaced by TeX code), press
CTRL-COMMAND-G in TeXShop.
This script should be located in a folder called EOM_Scripts together with
the perl scripts (written by Ulf Rehmann)
eom_replace_for_mac.pl
eom_refs.pl
In case a different folder is used, please change this below.
The two perl scripts need to be made executable. In order to do this,
open the Terminal app and type
cd Documents/EOM_Scripts/
then press <ENTER> and type
chmod u+x eom_replace_for_mac.pl
then press <ENTER> and type
chmod u+x eom_refs.pl
then press <ENTER>
Now you can quit the Terminal app.
*)
-- enter location of perl scripts here
set perlpath to "~/Documents/EOM_Scripts"
-- ACTUAL SCRIPT STARTS BELOW
----------------------------------------------------------------------------------------------------
-- copy TeXShop front document into script_source
tell application "TeXShop"
set script_source to text of front document as «class utf8»
end tell
-- make a temporary file on which the perl scripts can operate
set tempfile to make_temp_file()
-- copy script_source into the temporary file
write_to_temp_file(POSIX file tempfile, script_source)
-- replace img strings by $•$ (inline maths) and table strings by $$•$$ (display maths)
set tempstuff to (do shell script "cd " & perlpath & "; ./eom_replace_for_mac.pl " & " < " & quoted form of tempfile)
-- replace content of tempfile with tempstuff
write_to_temp_file(POSIX file tempfile, tempstuff)
-- apply perl script (clean up references) to temporary file with output into a variable called tempstuff
set tempstuff to (do shell script "cd " & perlpath & "; ./eom_refs.pl " & " < " & quoted form of tempfile)
-- replace content of tempfile with tempstuff and convert to UNIX (LF) format; uses flip
write_to_temp_file(POSIX file tempfile, tempstuff)
do shell script "/bin/tcsh -c '~/Library/TeXShop/bin/flip -u " & tempfile & "'"
-- copy everything back to the front document of TeXShop
tell application "TeXShop"
set text of front document to tempstuff as «class utf8»
end tell
-- move the cursor to the first "slot" $•$ or $$•$$
tell application "TeXShop"
activate
end tell
tell application "System Events"
tell process "TeXShop"
key code 126 using command down
key code 3 using {command down, control down}
end tell
end tell
-- stuff below used to create temporary files and write to them
on make_temp_file()
set folder_name to path to temporary items
set file_name to "eom_temp" & (random number from 100000 to 999999)
set existing_file_names to list folder folder_name
repeat while file_name is in existing_file_names
set file_name to "eom_temp" & (random number from 100000 to 999999)
end repeat
return (POSIX path of folder_name) & file_name
end make_temp_file
on write_to_temp_file(temp_file, temp_text)
set file_ref to open for access temp_file with write permission
set eof file_ref to 0
write temp_text to file_ref as «class utf8»
close access file_ref
end write_to_temp_file
How to Cite This Entry:
Eom clean up.txt. Encyclopedia of Mathematics. URL: http://encyclopediaofmath.org/index.php?title=Eom_clean_up.txt&oldid=32265
Eom clean up.txt. Encyclopedia of Mathematics. URL: http://encyclopediaofmath.org/index.php?title=Eom_clean_up.txt&oldid=32265