[OS X TeX] text encoding corruption in TeXShop editor
Claus Gerhardt
gerhardt at math.uni-heidelberg.de
Wed Sep 13 18:30:14 CEST 2006
Below is an Applescript that will prepend the lines
%!TEX encoding = IsoLatin
%
to the front most document in TS. The above lines have first to be
saved in the file "~/Documents/encoding". If you choose a different
destination the Applescript has to be modified accordingly.
Claus
--AppleScript
-- Apply only to an already saved file
-- Claus Gerhardt, September 2006
(*This script prepends the text in the file "~/Documents/encoding"
to the text of the front most document in TeXShop and tells TeXShop
to open the changed document. The script needs BBEdit.*)
tell application "TeXShop"
get path of document of window 1
set fileName to result
end tell
set {baseName, texName, pdfName, namePath, dirName, dirNameunquoted,
logName, logPath, rtfName, docName} to setnametsn(fileName)
tell application "TeXShop"
close window docName
end tell
set theFile to POSIX file fileName as string
tell application "BBEdit"
open the file theFile
get file of window 1
set filepath to result
set fileName to POSIX path of filepath as string
set fileName1 to fileName
end tell
set scriptPath to (do shell script "dirname " & "~/Documents/ex")
set scriptPath to scriptPath & "/encoding"
set encodingName to scriptPath as POSIX file
tell application "BBEdit"
open the file encodingName
select text 1 of text window 1
extended copy of selection
close document of text window 1
end tell
tell application "BBEdit"
select text 1 of text window 1
extended copy selection appending to clipboard "yes"
activate
paste
save window 1
close document of text window 1
end tell
set theFile to POSIX file fileName1
tell application "TeXShop"
activate
open theFile
end tell
on setnametsn(x)
set n to (number of characters of contents of x)
set fileNamequoted to quoted form of x
set windowName to do shell script "basename " & fileNamequoted
set m to (number of characters of contents of windowName)
set dirName to quoted form of (characters 1 thru (n - m - 1) of x as
string)
set dirNameunquoted to (characters 1 thru (n - m - 1) of x as string)
set theText to contents of windowName as string
set n to (number of characters of contents of theText)
set i to n as number
repeat while i > 0
if character i of theText is equal to "." then
set m to i
exit repeat
else
set i to (i - 1)
end if
end repeat
set baseName to (characters 1 thru (m - 1) of theText as string)
set texName to baseName & ".tex"
set namePath to dirNameunquoted & "/" & baseName as string
set pdfName to namePath & ".pdf" as string
set rtfName to namePath & ".rtf" as string
set logPath to namePath & ".log" as string
set logName to baseName & ".log" as string
set theFile to POSIX file x as string
tell application "Finder"
get displayed name of the file theFile
end tell
set docName to result
return {baseName, texName, pdfName, namePath, dirName,
dirNameunquoted, logName, logPath, rtfName, docName} as list
end setnametsn
On Sep 13, 2006, at 14:12, Gianluca Gorni wrote:
>
> Hello!
>
> I commonly have to work with TeX source files written by students
> on Windows
> in Latin1 encoding. My problem is how to deal with them in TeXShop
> as easily
> as possible. My TeXShop is set to MacOS encoding by default.
>
> In BBEdit there is the menu item "reopen using encoding...". I
> couldn't find
> an equivalent in TeXShop. The only way (that I know of) to display
> a file correctly
> is to close it and then reopen it from the menu, selecting the
> encoding from
> the open file panel.
>
> For files that I have to open repeatedly over time I thought I had
> found a way:
> in TeXShop I typed
>
> %!TEX encoding = IsoLatin
>
> at the top of the file. This way, I thought, next time I opened the
> file
> by double-clicking, it would display correctly.
>
> I was wrong. It seems that TeXShop had not simply added the new top
> line,
> but it had changed the code of all the non-ascii characters. Now
> the file did not
> display correctly in any editor and any encoding that I tried.
> The compiled pdf also came out wrong.
>
> In BBEdit, adding
> %!TEX encoding = IsoLatin
> does not corrupt the file, and display will be fine in TeXShop.
>
> Best regards,
> Gianluca Gorni
>
> ------------------------- Info --------------------------
> Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
> & FAQ: http://latex.yauh.de/faq/
> TeX FAQ: http://www.tex.ac.uk/faq
> List Archive: http://tug.org/pipermail/macostex-archives/
>
------------------------- Info --------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
More information about the macostex-archives
mailing list