Skip to content

Instantly share code, notes, and snippets.

@satomacoto
Created January 12, 2012 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satomacoto/1601133 to your computer and use it in GitHub Desktop.
Save satomacoto/1601133 to your computer and use it in GitHub Desktop.
TeX2PDF for CotEditor
(*
TeX2PDF for CotEditor
編集中のTeXファイルをDrag & Drop pTeX (http://www2.kumagaku.ac.jp/teacher/herogw/)でタイプセットするスクリプト。texファイルはどこかに保存されている必要があります。デフォルトではpTeX.appは“アプリケーション”フォルダにインストールされているとします。pTeX.appのスクリプトを参考にしました。少し書き換えればportsなどでインストールしたpTeXにも対応できるかもしれません。
*)
(* written by satomacoto. 2010.1.26 *)
tell application "CotEditor"
if exists front document then
set theposix to "/Applications/pTeX.app/"
set thisfile to path of front document as Unicode text
if (thisfile is not "") then
set thecom1 to (do shell script "PLATEX='platex';CLASS=`sed -n '/documentclass/p' " & thisfile & " | sed '/%.*documentclass/d' | sed -n '1p'`;case $CLASS in *{u*) PLATEX='uplatex' ;; esac;echo $PLATEX")
set thisbase to (do shell script "/usr/bin/basename " & thisfile)
set thisdir to (do shell script "/usr/bin/dirname " & thisfile)
set thisbase1 to (do shell script "/usr/bin/basename " & thisfile & " .tex")
set thecode to (do shell script theposix & "teTeX/bin/nkf -g " & thisfile)
if thecode = "UTF-8" then
set thecom1 to thecom1 & " -kanji=utf8"
else if thecode = "EUC-JP" then
set thecom1 to thecom1 & " -kanji=euc"
else if thecode = "ISO-2022-JP" then
set thecom1 to thecom1 & " -kanji=jis"
else if thecode = "Shift_JIS" then
set thecom1 to thecom1 & " -kanji=sjis"
end if
tell application "Terminal"
activate
do script with command "cd " & thisdir & ";" & theposix & "teTeX/bin/" & thecom1 & space & thisbase & ";" & theposix & "teTeX/bin/dvipdfmx " & thisbase1 & ".dvi ; open -g -a Preview.app " & thisbase1 & ".pdf && exit"
end tell
end if
activate
end if
end tell
(*
TeX2PDF for CotEditor
編集中のTeXファイルをDrag & Drop pTeX (http://www2.kumagaku.ac.jp/teacher/herogw/)でタイプセットするスクリプト。texファイルはどこかに保存されている必要があります。デフォルトではpTeX.appは“アプリケーション”フォルダにインストールされているとします。pTeX.appのスクリプトを参考にしました。少し書き換えればportsなどでインストールしたpTeXにも対応できるかもしれません。BibTeXに対応しています。
*)
(* written by satomacoto. 2010.1.26 *)
tell application "CotEditor"
if exists front document then
set theposix to "/Applications/pTeX.app/"
set thisfile to path of front document as Unicode text
if (thisfile is not "") then
set thecom1 to (do shell script "PLATEX='platex';CLASS=`sed -n '/documentclass/p' " & thisfile & " | sed '/%.*documentclass/d' | sed -n '1p'`;case $CLASS in *{u*) PLATEX='uplatex' ;; esac;echo $PLATEX")
set thisbase to (do shell script "/usr/bin/basename " & thisfile)
set thisdir to (do shell script "/usr/bin/dirname " & thisfile)
set thisbase1 to (do shell script "/usr/bin/basename " & thisfile & " .tex")
set thecode to (do shell script theposix & "teTeX/bin/nkf -g " & thisfile)
if thecode = "UTF-8" then
set thecode to " -kanji=utf8 "
else if thecode = "EUC-JP" then
set thecode to " -kanji=euc "
else if thecode = "ISO-2022-JP" then
set thecode to " -kanji=jis "
else if thecode = "Shift_JIS" then
set thecode to " -kanji=sjis "
else
set thecode to " "
end if
tell application "Terminal"
activate
do script with command "cd " & thisdir & ";" & theposix & "teTeX/bin/" & thecom1 & thecode & thisbase & ";" & theposix & "teTeX/bin/jbibtex" & thecode & thisbase1 & ";" & theposix & "teTeX/bin/" & thecom1 & thecode & thisbase & ";" & theposix & "teTeX/bin/" & thecom1 & thecode & thisbase & ";" & theposix & "teTeX/bin/dvipdfmx " & thisbase1 & ".dvi ; open -g -a Preview.app " & thisbase1 & ".pdf && exit"
end tell
end if
activate
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment