TeXShop ã®æ¥æ¬èªãã«ããã¡ã€ã«ã®ã¢ãŒã«ã€ã (v2-4) ã§ãã
äœæ¥åœæã®æ¥è±å¯Ÿèš³ããã¹ããã¢ããããŠããŸãã
#Macros HelpïŒãã¯ãã»ãã«ãïŒ
##PreliminariesïŒãŸãããïŒ
âTeXShop macros and the Macro Editor are by Mitsuhiro Shishikura. Default Latex macros were created by Mitsuhiro Shishikura and Hirokazu Ogawa. Default Context macros were created by Hans Hagen.
ãâ ãTeXShop ãã¯ããšãã¯ããšãã£ã¿ã¯å®åå åºããã«ãããã®ã§ããããã©ã«ãã® LaTeX ãã¯ãã¯å®åå åºãããšå°å·åŒåãããäœæããŸãããããã©ã«ãã® ConTeXt ãã¯ã㯠Hans Hagen ããã«ãã£ãŠäœæãããŸããã
âThe available Macros depend on the typesetting engine chosen. If this engine is LaTeX, then a series of macros suitable for LaTeX will be displayed. If the engine is ConTeXT, then macros for ConTeXt will be displayed. When TeXShop is first installed, it has macros for only these two engines; the LaTeX macros will be displayed for all engines except ConTeXt.
ãâ ãã¿ã€ãã»ããã»ãšã³ãžã³ã®éžæã«ãã£ãŠãå©çšã§ãããã¯ãã¯ç°ãªããŸãããšã³ãžã³ã LaTeX ã«ããå Žåã LaTeX ã«é©ããäžé£ã®ãã¯ãã衚瀺ãããŸãããšã³ãžã³ã ConTeXT ã«ããã°ã ConTeXt çšã®ãã¯ãã衚瀺ãããŸãã TeXShop ãã€ã³ã¹ããŒã«ããåœåã¯ããã®ïŒã€ã®ãšã³ãžã³çšã®ãã¯ãã ããå ¥ã£ãŠããŸã ïŒ LaTeX çšã®ãã¯ãã¯ã ConTeXt ãé€ããã¹ãŠã®ãšã³ãžã³ã«å¯ŸããŠè¡šç€ºãããŸãã
âMacros come in two kinds. Some insert strings into the TeX source file; these macros are similar to buttons in the Latex panel. Other macros run Applescript scripts.
ãâ ããã¯ãã«ã¯ïŒçš®é¡ãããŸããã²ãšã€ã¯ TeX ã®ãœãŒã¹ãã¡ã€ã«ã«æååãæ¿å ¥ãããã®ã§ã ïŒ ãããããã¯ã㯠LaTeX ããã«ã®ãã¿ã³ãšäŒŒãŠããŸããããã²ãšã€ã®ãã¯ã㯠AppleScript ã®ã¹ã¯ãªãããå®è¡ããŸãã
âMacros are stored in ~/Library/TeXShop/Macros/Macros_Latex.plist and ~/Library/TeXShop/Macros/Macros_Context.plist. If these files are missing when TeXShop runs, default macro files are created there. These files are ordinary text files, so it can be opened and inspected with TeXShop. This is usually not necessary because the files are best manipulated with the Macro editor.
ãâ ããã¯ã㯠~/Library/TeXShop/Macros/Macros_Latex.plist ãš ~/Library/TeXShop/Macros/Macros_Context.plist ã«æ ŒçŽãããŠããŸãã TeXShop ãèµ·åããéã«ãããã®ãã¡ã€ã«ããªããã°ãããã©ã«ãã»ãã¯ãã®ãã¡ã€ã«ãåè¿°ã®å Žæã«äœãããŸãããããã®ãã¡ã€ã«ã¯ããæ®éã®ããã¹ããã¡ã€ã«ãªã®ã§ã TeXShop ã§éããã調ã¹ããã§ããŸããããã¯éåžžã¯äžå¿ èŠãªããšã§ãââãšããã®ãããã¯ããšãã£ã¿ã§æ±ãã®ããã¡ã°ãã§ãããã
âThe Macro editor modifies macros stored in Macros_Latex.plist and Macros_Context.plist when one of these typesetting engines is chosen. But if another typesetting engine like TeX is chosen, then the Macro editor will replace the default Latex macro set with a set defined by the user for TeX, storing the results in Macros_Tex.plist and leaving Macros_Latex.plist unchanged.
ãâ ãMacros_Latex.plist ãš Macros_Context.plist ã«æ ŒçŽãããŠãããã¯ãã¯ãããããã®ã¿ã€ãã»ããã»ãšã³ãžã³ãéžæãããŠãããšãã«ãã¯ããšãã£ã¿ã§ä¿®æ£ã§ããŸããããããã TeX ã®ãããªä»ã®ã¿ã€ãã»ããã»ãšã³ãžã³ãéžã°ããŠãããšãã«ã¯ããã¯ããšãã£ã¿ã¯ãããã©ã«ãã® LaTeX ãã¯ãã®ã»ããããŠãŒã¶ã TeX çšã«å®çŸ©ããã»ããã«çœ®ãæããŸãââãã®çµæ㯠Macros_Tex.plist ã«ä¿åãããŸãããããšã® Macros_Latex.plist ã¯å€æŽãããã«æ®ããŸãã
âWhen you define useful Macros and wish to give them to others, simply open the Macro Editor and choose "Save selection to file..." in the Macro menu. This will create a file in any location you wish. To distribute your macros, send this file.
ãâ ãããªãã䟿å©ãªãã¯ããå®çŸ©ãããããä»ã®äººãã¡ã«æž¡ããããšæã£ããšãã¯ããã¯ããšãã£ã¿ãéãããã¯ãã¡ãã¥ãŒãããéžæãããã¯ãããã¡ã€ã«ã«ä¿å...ããéžã¹ã°ããã ãã®ããšã§ããä¿åå ã¯ãããã®å Žæã§ãããŸããŸããããã¯ããé åžããã«ã¯ããã®ãã¡ã€ã«ãéããŸãã
âTo add macros created by others to your list of macros, open the Macro Editor and choose "Add macros from file...". Then use the Macro Editor to arrange the macros as you desire.
ãâ ãä»ã®äººãã¡ãäœæãããã¯ãããã¯ããªã¹ãã«è¿œå ããã«ã¯ããã¯ããšãã£ã¿ãéããããã§ããã¡ã€ã«ãããã¯ããè¿œå ...ããéžæããŸãããã®åŸãã¯ããšãã£ã¿ã䜿ã£ãŠãã¯ãã奜ããªããã«é åããŸãã
##Understanding Default MacrosïŒããã©ã«ãã®ãã¯ããç解ããïŒ
âThe best way to understand default macros is to examine their definition with the Macro Editor. For example, consider the macro titled "Begin/End." Suppose you wish to use an environment like the theorem environment. Type the word "theorem" and select it. Then choose the "Begin/End" macro. The word "theorem" will be replaced with the text
ãâ ãããã©ã«ãã®ãã¯ããç解ãããã¡ã°ãããæ¹æ³ã¯ããã®å®çŸ©ããã¯ããšãã£ã¿ã§èª¿ã¹ãŠã¿ãããšã§ããããšãã°ãBegin/Endããšé¡ããããã¯ãã«ã€ããŠèããŠã¿ãŸãããã theorem ç°å¢ã®ãããªç°å¢ã䜿ããããšããŸãã ãtheoremããšããåèªãæã¡èŸŒã¿ããããéžæããŠãã ããããããŠãBegin/Endããã¯ããéžã³ãŸãã ãtheoremããšããèªãã次ã®ãããªããã¹ãã«çœ®ãæããããŸãââ
\begin{theorem}
\end{theorem}
âwith the cursor placed on the line between this pair.
ãâ ãã«ãŒãœã«ã¯ begin ãš end ã®éã«é 眮ãããŠããŸãã
âNow examine the begin/end macro code:
ãâ ãã§ã¯ãBegin/Endããšãããã¯ãã®ã³ãŒãã調ã¹ãŠã¿ãŸãïŒ
\begin{#SEL#}
#INS#
\end{#SEL#}
âText in the macro will be inserted into the source file. Each occurrence of the string #SEL# will be replaced by the text selected when the macro was invoked. If no text was selected, #SEL# will be replaced with an empty string. The cursor will be placed at the end of the inserted text unless the text contains the string #INS#, in which case the cursor will be placed at that location.
ãâ ããã¯ãå ã®ããã¹ãããœãŒã¹ãã¡ã€ã«ã«æ¿å ¥ãããã#SEL# ãšããæååã¯ããããã«ããã¯ããå®è¡ããããšãã«éžæãããŠããããã¹ãã§çœ®ãæãããããããããã¹ããäœãéžæãããŠããªããã°ã#SEL# ã¯ç©ºã£ãœã®æååã§çœ®ãæãããããã«ãŒãœã«ã¯æ¿å ¥ããããã¹ãã®æåŸã«çœ®ããããã#INS# ãšããæååãå«ãŸããŠããå Žåã«ã¯ãããã«ã«ãŒãœã«ãé 眮ãããã
âUsing this knowledge, it is easy to understand and modify the default macros.
ãâ ããããããã£ãŠããã°ãããã©ã«ãã®ãã¯ããç解ãããä¿®æ£ãããããã®ã¯ç°¡åãªããšã§ãã
##Rearranging the Macro MenuïŒãã¯ãã®é ç®åã䞊ã¹æ¿ããïŒ
âOpen the Macro Editor and examine the macro menu on the left. It is shown in an outline view similar to the view of the file system obtained by choosing the middle button of the View tab in the Finder. To rearrange items, drag them from one spot to another. Notice that items can be placed at different levels by sliding left and right. To rename an item, select it in the outline view and type a new name in the field at the top right.
ãâ ããã¯ããšãã£ã¿ãéããŠãå·ŠåŽã«ãããã¯ãã®é ç®åã®äžèŠ§ãèŠãŠã¿ãŸããããFinder ã®ãªã¹ã衚瀺ã®ãããªãã¢ãŠãã©ã€ã³è¡šç€ºã«ãªã£ãŠããŸããé ç®ã䞊ã¹æ¿ããã«ã¯ãããå Žæããå¥ã®å Žæãžãšé ç®ããã©ãã°ããŸããé ç®ãå·Šãªããã¯å³ã«ãããããšã§ãç°ãªããã©ã«ãéå±€ã«çœ®ãããšãã§ããŸããé ç®åãå€æŽããã«ã¯ãã¢ãŠãã©ã€ã³è¡šç€ºã®äžã§ãã®é ç®ãéžæããå³äžã«ããé ç®åã®ãã£ãŒã«ãã«æ°ããååãå ¥ããŸãã
##Defining New MacrosïŒæ°ãããã¯ããå®çŸ©ããïŒ
âNew items, new submenus, and new separators can be created by the buttoms at the bottom left. A little practice illustrates the basic behavior of the editor. Submenus can be created to any level.
ãâ ãæ°èŠã®é ç®ïŒæ°èŠãã¯ãïŒãæ°èŠã®ãµãã¡ãã¥ãŒïŒãµãã¡ãã¥ãŒïŒãæ°èŠã®åºåãç·ïŒåºåãïŒãªã©ã¯ãå·Šäžã®ãã¿ã³ã§äœæã§ããŸããå°ãããã£ãŠã¿ãã°ããšãã£ã¿ã®åºæ¬çãªåäœã¯æããã«ãªãã§ãããããµãã¡ãã¥ãŒã¯ã©ã®éå±€ã«ãäœæã§ããŸãã
âAny particular item can be assigned a keyboard equivalent using the buttons on the right side of the menu. The result will immediately appear in the outline view. However, these assignments cannot duplicate key combinations already used by TeXShop menus. If they do, the new keyboard shortcut will be ignored.
ãâ ããããã®é ç®ã«ããäžèŠ§è¡šã®å³äžã«ãããã¿ã³é¡ã䜿ã£ãŠåå¥ã«ããŒæäœãå²ãåœãŠãããšãã§ããŸããçµæã¯ããã«ã¢ãŠãã©ã€ã³è¡šç€ºå ã«ç€ºãããŸããããããªãããããããå²ãåœãŠã¯ã TeXShop ã®ã¡ãã¥ãŒã§ãã§ã«äœ¿ãããŠããã·ã§ãŒãã«ããããŒãšéè€ãããããšã¯ã§ããŸããããããéè€ããå Žåã¯ãæ°ããã»ãã®ã·ã§ãŒãã«ããã¯ç¡èŠãããŸãã
##AppleScript MacrosïŒ AppleScript ãã¯ãïŒ
âIf a macro begins with the string
ãâ ããã¯ãã次ã®ããããã®æååã§å§ãŸã£ãŠããå Žåââ
--AppleScript
--AppleScript direct
âthen the resulting applescript code will run when the Macro is chosen. For example, consider the macro titled "View pdf with Acrobat." Choosing this macro when the source file is active (and the pdf file has been created) will start Adobe Acrobat Reader and open the output pdf file in that program. The corresponding applescript code reads
ãâ ããã®ãã¯ããéžæãããšã AppleScript ã®ã³ãŒããå®è¡ãããŸãã ããšãã°ãView pdf with Acrobatããšé¡ããããã¯ããèããŠã¿ãŸãã ãœãŒã¹ãã¡ã€ã«ãã¢ã¯ãã£ãã«ãªã£ãŠããïŒå ã㊠pdf ãã¡ã€ã«ããã§ã«çææžã¿ã«ãªã£ãŠããïŒãšãã«ãã®ãã¯ããéžæãããšã Adobe Acrobat Reader ãç«ã¡äžãã£ãŠ pdf åºåãã¡ã€ã«ãéããŸãã ãã® AppleScript ã®ã³ãŒãã¯ã次ã®ããã«ãªã£ãŠããŸãââ
--AppleScript direct
tell application "Acrobat Reader 5.0"
activate
open POSIX file #PDFPATH#
end tell
âCommands beginning with "--AppleScript direct" are run directly by TeXShop. During the time this applescript is running, TeXShop's event loop is not active. Consequently, the script cannot call TeXShop to perform an action which might require user input. For example, it cannot ask TeXShop to run LaTeX, because if the LaTeX file has an error, the console will appear and wait for user input, but such input would not be recognized.
ãâ ãã--AppleScript directãã§å§ãŸãã³ãã³ãã¯ã TeXShop ã«ããçŽæ¥å®è¡ãããŸãããã® AppleScript ãå®è¡ãããŠããéã¯ã TeXShop ã®ã€ãã³ãã»ã«ãŒãã¯æå¹ã«ãªããŸããããããã£ãŠãã®ã¹ã¯ãªããã«ã¯ã TeXShop ãåŒã³åºããŠããŠãŒã¶ã®å ¥åãå¿ èŠãšãããããããªãåäœãè¡ãªãããããšã¯ã§ããŸãããããšãã°ã TeXShop ã« LaTeX ãå®è¡ããããèŠè«ããããšãã§ããŸããââãšããã®ãã LaTeX ãã¡ã€ã«ã«ãšã©ãŒããã£ãå Žåãã³ã³ãœãŒã«ã衚瀺ãããŠãŒã¶ã®å ¥åãåŸ ã¡ãŸãããããããå ¥åã¯ã§ããªãã®ã§ãã
âCommands beginning with "--AppleScript" are run by a small auxiliary program in the TeXShop application bundle. Such commands can ask TeXShop to perform actions which might require user input, because in that case the auxiliary program will temporarily halt but TeXShop will remain active.
ãâ ãã--AppleScriptãã§å§ãŸãã³ãã³ãã¯ã TeXShop ã«çµã¿èŸŒãŸããŠããå°ããªè£å©ããã°ã©ã ã«ããå®è¡ãããŸããããããã³ãã³ãã¯ããŠãŒã¶ã®å ¥åãå¿ èŠãšãããããããªãåäœãè¡ãªãããšã TeXShop ã«èŠæ±ã§ããŸãââãšããã®ãããã®å Žåãè£å©ããã°ã©ã ã¯äžæçã«åæ¢ããŸããã TeXShop ã¯ã¢ã¯ãã£ãã®ãŸãŸã ããã§ãã
âThus the syntax "--AppleScript direct" is appropriate for routine macros, but "--AppleScript" may be needed for fancy ones.
ãâ ããªã®ã§ã--AppleScript directãæ§æã¯ã«ãŒãã£ã³ã»ãã¯ãã«é©ããŠããŸãããæã®èŸŒãã ãã¯ãã«ã¯ã--AppleScriptããå¿ èŠãšãªãã§ãããã
##Default AppleScript MacrosïŒããã©ã«ãã® AppleScript ãã¯ãïŒ
âTeXShop comes with an extended collection of Applescripts by Will Robertson, Claus Gerhardt and others. Some of these scripts automate workflow when a series of typesetting commands must be issued in sequence. By copying and modifying the scripts, users can construct scripts appropriate for their own workflow.
ãâ ãTeXShop ã«ã¯ Will Robertson ããã Claus Gerhardt ããããã®ä»ã®äººãã¡ã«ãã AppleScript ã®åºæ±ãªã³ã¬ã¯ã·ã§ã³ãä»å±ããŠããŸãããããã®ã¹ã¯ãªããã®ããã€ãã¯ãäžé£ã®ã¿ã€ãã»ããã»ã³ãã³ããé ãè¿œã£ãŠå®è¡ããããšããã¯ãŒã¯ãããŒãèªååããŸããã¹ã¯ãªãããè€è£œãããä¿®æ£ãããããããšã§ãŠãŒã¶ã¯ãããããã®ã¯ãŒã¯ãããŒã«é©ããã¹ã¯ãªãããçµã¿ç«ãŠãããšãã§ããŸãã
âIn this section, we will describe some of these scripts.
ãâ ããã®ã»ã¯ã·ã§ã³ã§ã¯ãããããã¹ã¯ãªããã®ããã€ãã«ã€ããŠè¿°ã¹ãŸãã
âColumn Macros, Insert Reference, Open Quickly:
ãâ ãColumn Macros ã» Insert Reference ã» Open Quickly
âThese macros are by Will Robertson. The first provides a very convenient way to construct an arbitrary matrix or table. The second searches through the current file for \label{...} commands and then pops up a list from which you may insert a reference label, wrapped in an (optional) customizable LaTeX command. The final macro allows you to rapidly open any file in the directory of the current source file.
ãâ ããããã®ãã¯ã㯠Will Robertson ããã«ãããã®ã§ããæåã®ãã®ã¯ãä»»æã®è¡åãããŒãã«ããããããã®ã«ãšãŠã䟿å©ã§ãã次ã®ãã®ã¯ãçŸåšã®ãã¡ã€ã«å šäœãã \label{...} ã³ãã³ããæ¢ãåºããŠãªã¹ã衚瀺ããã®ã§ããã®äžããåç §ã©ãã«ãæ¿å ¥ãããããããïŒä»»æã®ïŒã«ã¹ã¿ãã€ãºå¯èœãª LaTeX ã³ãã³ãã§å²ãã ãã§ããŸããæåŸã®ãã¯ãã¯ãäœæ¥äžã®ãœãŒã¹ãã¡ã€ã«ããããã£ã¬ã¯ããªå ã®ãã¡ã€ã«ãææ©ãéããŸãã
âConvert to Mac, Convert to Unix, Convert to Windows:
ãâ ãConvert to Mac ã» Convert to Unix ã» Convert to Windows
âIn the early days, teletype terminals were used for communication. The ascii character set still has remnants from those days; for instance 0x07 rings the teletype bell. The character 0x0a was a line feed which turned the carriage to the next line and the character 0x0d was a carriage return which pulled the carriage back to the start of the line. To get a line feed, one used the sequence 0x0d 0x0a.
ãâ ãåæã®é ã¯ããã¬ã¿ã€ã端æ«ãéä¿¡ã«äœ¿ãããŠããŸããã ascii æåã»ããã¯ããŸã ã«ãã®é ã®åæ®ãããšã©ããŠããŸã ïŒ ããšãã° 0x07 ã¯ãã¬ã¿ã€ãã®ãã«ã鳎ãããŸãã 0x0a ãšãããã£ã©ã¯ã¿ã¯ãã£ãªããžã次è¡ãžéãã©ã€ã³ãã£ãŒãïŒ LF ïŒæ¹è¡ïŒã§ãããã 0x0d ãšãããã£ã©ã¯ã¿ã¯ãã£ãªããžãè¡ã®å é ãŸã§åŒãæ»ããã£ãªããžã»ãªã¿ãŒã³ïŒ CR ïŒè¡é 埩垰ïŒã§ãããè¡ãæ¹ããã«ã¯ãã²ãšã€ã¥ãã® 0x0d 0x0a ã䜿ããŸããã
âAfter the age of teletypes ended, computer manufacturers selected different subsets of these characters to indicate a line feed. In the Unix world, 0x0a was used, in the Windows world 0x0d 0x0a was used, and in the old Macintosh Classic world 0x0d was used. Apple's guidelines for Mac OS X state that programs should be able to automatically open files using any of these conventions. Most programs including TextEdit, TeXShop, etc., follow these guidelines. In TeXShop, new files are created using Unix conventions, but if you load a file created with Mac OS Classic and then add extra lines, old portions of the document will be saved with the Classic convention and new sections will have the Unix convention.
ãâ ããã¬ã¿ã€ãã®æ代ãçµãããšãã³ã³ãã¥ãŒã¿ã®è£œé è ãã¡ã¯ãæ¹è¡ã瀺ãã®ã«ããããã®ãã£ã©ã¯ã¿ã®ç°ãªãäžéšãéžã³åããŸããã UNIX ã§ã¯ 0x0aïŒ LF ïŒã䜿ããã Windows ã§ã¯ 0x0d 0x0aïŒ CR + LF ïŒãããããŠæã® Macintosh Classic ã§ã¯ 0x0dïŒ CR ïŒã䜿ãããŸããã Mac OS X çšã® Apple ã®ã¬ã€ãã©ã€ã³ã«ã¯ãããããä»æ§ã®ããããçšããããŠãããã¡ã€ã«ã§ãèªåçã«éããããã«ãã¹ãã ããšè¿°ã¹ãããŠããŸãã TextEdit ã TeXShop ãªã©ãå«ãã»ãšãã©ã®ããã°ã©ã ã¯ããã®ã¬ã€ãã©ã€ã³ã«ãããã£ãŠããŸãã TeXShop ã§ã¯ãæ°èŠæžé¡ã¯ Unix ã®æ¹è¡ã³ãŒãã§äœæãããŸããã Mac OS Classic ã§äœæãããã¡ã€ã«ãåã蟌ãã§æ°ããè¡ãä»ãå ããå Žåãææžã®å€ãéšå㯠Classic ã®æ¹è¡ã³ãŒãã§ä¿åãããæ°ããªç®æ㯠Unix ã®æ¹è¡ã³ãŒãã§ä¿åãããŸãã
âThese line feeds cause no trouble until you send a file to a friend using a different operating system. Many editors now understand multiple line feed conventions, so often you'll have no problems. But if you do, use the scripts above. Suppose the source file for a document is named MyFile.tex. Then "Convert to Mac" will create a new file named MyFile_Mac.tex with the same source code and Macintosh line feed conventions. "Convert to Unix" and "Convert to Windows" work the same way. All of these scripts call a binary program by Craig Stuart Sapp named "flip" in ~/Library/TeXShop/bin. See http://ccrma-www.stanford.edu/~craig/utility/flip/ for details.
ãâ ãããããæ¹è¡ã³ãŒãã¯ãç°ãªããªãã¬ãŒãã£ã³ã°ã»ã·ã¹ãã ã䜿ã£ãŠãã人ã«ãã¡ã€ã«ãéããªããããã¯ããã©ãã«ã®çš®ã«ãªã£ããã¯ããŸãããå€ãã®ãšãã£ã¿ãä»ã§ã¯è€æ°ã®æ¹è¡ã³ãŒãä»æ§ãç解ããŸããããããé »ç¹ã«åé¡ã«ã¯ãªããªãã§ããããããã©ãå°ã£ãããšã«ãªã£ãå Žåã«ã¯ãäžèšã®ã¹ã¯ãªããã䜿ã£ãŠãã ãããããã«ãœãŒã¹ãã¡ã€ã«ã®ååã MyFile.tex ãšããŠãããŸãããã ãConvert to Macãã¯ã MyFile_Mac.tex ãšããååã®ããœãŒã¹ã³ãŒãã¯åã㧠Macintosh ã®æ¹è¡ã³ãŒãã«ãªã£ãŠããæ°ãããã¡ã€ã«ãçæããŸãã ãConvert to UnixããšãConvert to Windowsããåæ§ã«æ©èœããŸãããããã®ã¹ã¯ãªããã¯ãã¹ãŠ ~/Library/TeXShop/bin ã«ãããflipããšããã Craig Stuart Sapp ã®äœã£ããã€ããªã»ããã°ã©ã ãåŒã³åºããŸãã詳现ã«ã€ããŠã¯ http://ccrma-www.stanford.edu/~craig/utility/flip/ ãåç §ããŠãã ããã
âOther Scripts->Bibliography:
ãâ ãOther Scripts->Bibliography
âProcessing a file with a bibliography requires multiple typesetting operations. First Latex is run to create an .aux file. Then Bibtex is run and uses this file to create .bbl and .blg files. Latex is run again to add the bibliography to the document. Latex is run a final time to update the references to the bibliography in the text.
ãâ ãåèæç®ç®é²ã®ãããã¡ã€ã«ãåŠçããã«ã¯ãæ°åºŠã®ã¿ã€ãã»ããæäœãå¿ èŠã«ãªããŸããæåã« LaTeX ãå®è¡ã㊠.aux ãã¡ã€ã«ãäœãããããã Bibtex ãå®è¡ãã.aux ãã¡ã€ã«ã䜿ã£ãŠ .bbl ãã¡ã€ã«ãš .blg ãã¡ã€ã«ãäœãã LaTeX ããµããã³å®è¡ããŠææžã«åèæç®ç®é²ãä»ãå ãããæåŸã« LaTeX ãå®è¡ããŠæ¬æäžã®ç®é²ã®åç §ãæŽæ°ããã
âThe "Bibliography" command does all of these things one by one. First it saves the file. Then it runs latex->bibtex->latex->latex. Finally it updates the preview display.
ãâ ããBibliographyãã³ãã³ãã¯ã以äžã®ããšãã²ãšã€ãã€è¡ãªããŸãããŸãæåã«ãã¡ã€ã«ãä¿åããŸãããã㊠latex -> bibtex -> latex -> latex ã®é ã«å®è¡ããŸããæåŸã«ãã¬ãã¥ãŒç»é¢ãæŽæ°ããŸãã
âhtlatexc, htlatexr:
ãâ ãhtlatexc ã» htlatexr
âTex4ht is a TeX program which converts a latex document into a web page. The source can be a standard Latex file and can include eps illustrations. The end result is an html page and a large number of gif files. The script command "htlatexc" saves the source documents, runs htlatex, and opens the resulting html file in Safari. Thus it behaves like a new TeXShop typesetting command, except that it was constructed by a user without waiting for new TeXShop code!
ãâ ãTex4ht ã¯ã LaTeX ææžããŠã§ãããŒãžã«å€æãã TeX ããã°ã©ã ã§ãããœãŒã¹ã¯æšæºç㪠LaTeX ãã¡ã€ã«ã§ããã eps 圢åŒã®ã€ã©ã¹ããå«ãã§ããŠãããŸããŸãããæçµçãªçµæ㯠html ããŒãžãšãªããå€æ°ã® gif ãã¡ã€ã«ãå«ãŸããŠããŸããã¹ã¯ãªããã³ãã³ããhtlatexcãã¯ããœãŒã¹ææžãä¿åãã htlatex ãå®è¡ããçµæã® html ãã¡ã€ã«ã Safari ã§éããŸããã€ãŸãããã¯ã TeXShop ã®æ°ããã¿ã€ãã»ããã»ã³ãã³ãã®ããã«åäœããŸãââ TeXShop ã®æ°ããã³ãŒããåŸ ããã«ãŠãŒã¶ã«ãã£ãŠæ§ç¯ãããããšããããšãé€ãã°ïŒ
âWhen using these scripts, it is not necessary to use the package text4ht since this package will automatically be loaded. The script htlatexc calls htlatex without additional options. The script htlatexr calls it with the option "-r", which tells the program to recreate any .gifs which already exist.
ãâ ããããã®ã¹ã¯ãªããã䜿ãéã«ã¯ã Tex4ht ããã±ãŒãžã䜿çšããå¿ èŠã¯ãããŸããââãã®ããã±ãŒãžã¯èªåçã«èªã¿èŸŒãŸããŸããã¹ã¯ãªãã htlatexc ã¯ãè¿œå ãªãã·ã§ã³ãªã㧠htlatex ãåŒã³åºããŸããã¹ã¯ãªãã htlatexr ã¯ãããªãã·ã§ã³ã-rããä»ããŠåŒã³åºããŸãââããã¯ãã§ã«ãããã¹ãŠã® .gif ãã¡ã€ã«ãåçæããããããã°ã©ã ã«åœããŸãã
âpdfselectc:
ãâ ãpdfselectc
âThis script runs the shell script pdfselect to create pdf files containing only certain selected pages of a document. When it is run, a dialog appears asking for the number of pdf files to be created. Suppose we answer 3. Next a dialog appears asking for the range for the first document. Suppose we answer 5:8. A dialog appears asking for the range of the second document. Suppose we answer 10. A dialog asks for the range of the third document. Suppose we answer 20:30. We will then obtain three documents, one containing pages 5 - 8 of the original, one containing page 10, and one containing pages 20 - 30.
ãâ ããã®ã¹ã¯ãªããã¯ãã·ã§ã«ã¹ã¯ãªãã pdfselect ãå®è¡ããææžã®äžããéžæããããŒãžã®ã¿ãå«ã pdf ãã¡ã€ã«ãäœæããŸãããããå®è¡ãããšãäœæãã pdf ãã¡ã€ã«ã®æ°ãå°ãããã€ã¢ãã°ã衚瀺ãããŸãããããã« 3 ãšããŠã¿ãŸããããã€ã¥ããŠæåã®ææžã®ããŒãžç¯å²ãå°ãããã€ã¢ãã°ã衚瀺ãããŸããããã 5:8 ãšããŸãã次ã«ç¬¬ïŒã®ææžã®ããŒãžç¯å²ãå°ãããã€ã¢ãã°ã衚瀺ãããŸããããã 10 ãšããŸããæåŸã«ç¬¬ïŒã®ææžã®ããŒãžç¯å²ãå°ãããã€ã¢ãã°ã衚瀺ãããŸããããã 20:30 ãšããŸããããã§ïŒã€ã®ææžãåŸãããããšã«ãªããŸãââã²ãšã€ã«ã¯å ã®ææžã®ïŒãïŒããŒãžããããã²ãšã€ã«ã¯10ããŒãžç®ãããããŠæåŸã®ã²ãšã€ã«ã¯20ã30ããŒãžãå«ãŸããŠããŸãã
âmpostc, mpostcpl, latex-makeindex-mpost:
ãâ ãmpostcã»mpostcpl ã» latex-makeindex-mpost
âThe script mpostc runs mpost and then pdflatex; the script mpostcpl runs pdflatex, and then mpost, and then pdflatex again. See the TeXShop help file Advanced: Context and Metapost for an example of the use of these three commands in sequence.
ãâ ãã¹ã¯ãªãã mpostc 㯠mpost ãå®è¡ããåŸã§ pdflatex ãå®è¡ããŸã ïŒ ã¹ã¯ãªãã mpostcpl 㯠pdflatex ãå®è¡ããåŸã§ mpost ãå®è¡ãããµããã³ pdflatex ãå®è¡ããŸãããã®ïŒã€ã®ã³ãã³ããé ã ã«çšããäŸã«ã€ããŠã¯ã TeXShop ãã«ãã®ãäžçŽåãã®ãã«ããã«ãããConTeXt ãš MetaPostããåç §ããŠãã ããã
âThe script latex-makeindex-mpost saves the source and runs pdflatex, makeindex, mpost, and pdflatex again, opening relevant log files in the process.
ãâ ãã¹ã¯ãªãã latex-makeindex-mpost ã¯ããœãŒã¹ãä¿åãã pdflatex, makeindex, mpost, ãããŠããäžåºŠ pdflatex ãå®è¡ãããã®éçšã§åœè©²ã®ãã°ãã¡ã€ã«ãéããŸãã
##Defining AppleScript MacrosïŒ AppleScript ãã¯ããå®çŸ©ããïŒ
âAppleScript syntax is a subject all its own. To learn more about it, read one of several books on the subject. If you installed the developer tools which come with Mac OS X, there is an online book about AppleScript in the Developer folder.
ãâ ãAppleScript ã®ææ³ã¯ããèªäœã§ã²ãšã€ã®ããŒãã§ãã AppleScript ã«ã€ããŠããã«åŠã¶ã«ã¯ãé¢é£æ¬ãã©ããïŒåèªãã§ã¿ãŠãã ããã Mac OS X ã«ä»å±ããããããããŒã»ããŒã«ãºãã€ã³ã¹ããŒã«ããŠããã®ã§ããã°ã AppleScript ã«ã€ããŠã®ãªã³ã©ã€ã³æ¬ã Developer ãã©ã«ãã®äžã«å ¥ã£ãŠããŸãã
âWhen TeXShop interpretes an applescript macro, it first replaces any string #FILEPATH#, #PDFPATH#, #DVIPATH#, #PSPATH#, #LOGPATH#, #AUXPATH# with the complete path name of the source tex file, pdf file, dvi file, ps file, log file, or aux file respectively. Similarly, the strings #INDPATH#, #BBLPATH#, and #HTMLPATH# are replaced with the complete path name of the ind file, bbl file, or html file.
ãâ ãTeXShop ã AppleScript ãã¯ããå®è¡ãããšãã«ã¯ãæåã« #FILEPATH#, #PDFPATH#, #DVIPATH#, #PSPATH#, #LOGPATH#, #AUXPATH# ãšãã£ãæååããã¹ãŠã TeX ãœãŒã¹ãã¡ã€ã«ã pdf ãã¡ã€ã«ã dvi ãã¡ã€ã«ã ps ãã¡ã€ã«ã log ãã¡ã€ã«ãããã㯠aux ãã¡ã€ã«ããããã®å®å šãã¹åã§çœ®ãæããŸããåæ§ã«æåå #INDPATH# ã» #BBLPATH# ã» #HTMLPATH# ã¯ã ind ãã¡ã€ã«ã bbl ãã¡ã€ã«ã html ãã¡ã€ã«ã®å®å šãã¹åã«çœ®ãæããããŸãã
âIn addition, any string #NAMEPATH# is replaced with the complete path name of the source tex file minus its extension, and any string #DOCUMENTNAME# is replaced with the display name of the current document. This last replacement is somewhat subtle; it gives the title of the document as shown at the top of the source window. If a document was saved with the "hide extension" box checked, #DOCUMENTNAME# will contain only the document name. But if the document was saved without checking "hide extension", #DOCUMENTNAME# will contain the document name and extension. This information can be used to locate the calling document for Applescript code as follows:
ãâ ãå ããŠãæåå #NAMEPATH# ã¯ãã¹ãŠã TeX ãœãŒã¹ãã¡ã€ã«ã®æ¡åŒµåãçããå®å šãã¹åã§çœ®ãæããããŸãããæåå #DOCUMENTNAME# ã¯ãã¹ãŠãçŸåšã®ææžã®è¡šç€ºåã§çœ®ãæããããŸãããã®æåŸã®çœ®ãæãã¯ãããã¶ã埮åŠãªãã®ã§ã ïŒ ãœãŒã¹ãŠã€ã³ããŠã®äžéšã«ç€ºãããŠããææžã®ã¿ã€ãã«ã䜿ãããã®ã§ãããããæ¡åŒµåãé ããã«ãã§ãã¯ãå ¥ããŠææžãä¿åããŠããå Žåã«ã¯ã#DOCUMENTNAME# ã¯ææžåã®ã¿ã«ãªããŸããããã©ããæ¡åŒµåãé ããã«ãã§ãã¯ãå ¥ããã«ææžãä¿åããŠããã°ã#DOCUMENTNAME# ã«ã¯ææžåïŒæ¡åŒµåãå ¥ããŸãããã®ããšã¯ã次ã®ããã« AppleScript ã³ãŒãã§åŒã³åºãææžãèŠã€ããã®ã«äœ¿ããŸãïŒ
tell document #DOCUMENTNAME# of application "TeXShop"
latex
end tell
âThere are at least two ways to write Applescript commands. Applescript can run shell commands, so after preliminary processing with an applescript, a shell command can be called to do the actual work. TeXShop comes with several examples of this technique; some of these examples will be explained in a later help section. Applescript commands can also call build-in TeXShop commands and thus work directly. A later section will give examples of this technique.
ãâ ãAppleScript ã³ãã³ããæžãæ¹æ³ã¯ãå°ãªããšãïŒã€ãããŸãã AppleScript ã¯ã·ã§ã«ã³ãã³ããå®è¡ã§ããã®ã§ã AppleScript ã§ååŠçãããåŸãã·ã§ã«ã³ãã³ããåŒã³åºããŠå®äœæ¥ããããããšãã§ããŸãã TeXShop ã«ã¯ãã®ææ³ã«ã€ããŠã®äŸãããã€ãä»å±ããŠããŸã ïŒ ããããäŸã®äžã«ã¯ããã«ãã®åŸç¯ã§èª¬æãããã®ããããŸãã AppleScript ã³ãã³ãã¯ã TeXShop ã«çµã¿èŸŒãŸããŠããã³ãã³ããåŒã³åºããŠçŽæ¥äœåãããããšãã§ããŸããåŸç¯ã§ã¯ãã¡ãã®ææ³ã®äŸã«ã€ããŠè§ŠããŸãã
âTeXShop understands the following commands:
ãâ ãTeXShop ã¯ä»¥äžã®ã³ãã³ããç解ããŸãïŒ
- typeset
- latex
- tex
- context
- bibtex
- makeindex
- metapost
- typesetinteractive
- latexinteractive
- texinteractive
- contextinteractive
- bibtexinteractive
- makeindexinteractive
- metapostinteractive
- taskdone
- refreshpdf
- refreshtext
- goto line
âThe first seven commands call TeXShop typesetting routines. These commands typeset continuously without stopping at errors. The next seven commands also call TeXShop typesetting commands, but this time if there is an error, the user is allowed to interact with the console. When a typesetting command is called, control returns to the applescript immediately without waiting until the operation is complete. The "taskdone" call returns NO if typesetting is still running, and YES when it is done. The calls "refreshpdf" and "refreshtext" cause pdf and text documents to display the latest version of their files on the screen. The "goto line" command tells the editor to select a given line; for example:
ãâ ãæåã®ïŒã€ã®ã³ãã³ã㯠TeXShop ã®ã¿ã€ãã»ããã»ã«ãŒãã³ãåŒã³åºããŸãããããã®ã³ãã³ãã¯ãšã©ãŒç®æã§æ¢ãŸãããšãªãã«ã¿ã€ãã»ãããç¶ç¶ããŸãã次ã®ïŒã€ã®ã³ãã³ãããŸã TeXShop ã®ã¿ã€ãã»ããã»ã³ãã³ãã§ããããã¡ãã¯ãããšã©ãŒãããã°ãã³ã³ãœãŒã«ã§å¯Ÿè©±çã«äœæ¥ãè¡ãªããŸããã¿ã€ãã»ããã»ã³ãã³ããåŒã³åºããããšãäœæ¥ãå®äºããã®ãåŸ ããã«ãã³ã³ãããŒã«ã¯ããã« AppleScript ã«æ»ããŸãã ãtaskdoneãã¯ãã¿ã€ãã»ããäžã¯ NO ãè¿ããå®äºãããš YES ãè¿ããŸãã ãrefreshpdfããšãrefreshtextãã¯ã pdf ããã³ããã¹ãææžãææ°ã®ç¶æ ã§ç»é¢ã«è¡šç€ºããŸãã ãgoto lineãã³ãã³ãã¯ãæå®ã®è¡ãéžæãããããšãã£ã¿ã«åœããŸã ïŒ ããšãã°ïŒ
tell document #DOCUMENTNAME# of application "TeXShop"
goto line 37
end tell
##Creating DialogsïŒãã€ã¢ãã°ãäœãïŒ
âAppleScript can create dialogs and act on user input. For example, insert the following script and test its behavior.
ãâ ãAppleScript ã§ãã€ã¢ãã°ãäœæãããŠãŒã¶ã®å ¥åã«å¿ããŠåäœããããã«ã§ããŸããããšãã°ã以äžã®ã¹ã¯ãªãããæžãå ¥ããŠããµããŸããè©ŠããŠã¿ãŠãã ããã
-- AppleScript
-- Use a dialog to enter user defined information into an applescript.
-- ãã€ã¢ãã°ã䜿ãããŠãŒã¶ã®å®ããããŒã¿ã AppleScript ã«åã蟌ã¿ãŸãã
-- There are two feedbacks possible 'text' and "choice of buttons".
-- ãããã¹ãããšããã¿ã³éžæãã«ããïŒã€ã®ãã£ãŒãããã¯ãå©çšå¯èœã§ãã
-- The returned information can be used to define corresponding variables.
-- è¿ãããããŒã¿ã¯è©²åœããå€æ°ãå®çŸ©ããã®ã«äœ¿ããŸãã
-- The number of buttons may not exceed three.
-- ãã¿ã³ã®æ°ã¯ïŒã€ãè¶
ããªãããã«ã
-- In the three examples below it is shown how to use text return, button return, and both.
-- 以äžã®ïŒã€ã®äŸã§ã¯ãããã¹ãããã¿ã³ãããã¹ãïŒãã¿ã³ã®äœ¿ãæ¹ã«ã€ããŠç€ºããŠããŸãã
activate
display dialog "Test dialog: type something below" default answerâŒ
"Hello World!" buttons {"A", "B", "C"} default button "B"
set theText to (the text returned of the result)
display dialog "Test dialog: type something below" default answerâŒ
"Hello World!" buttons {"A", "B", "C"} default button "B"
set theButton to (the button returned of the result)
display dialog "Test dialog: type something below" default answerâŒ
"Hello World!" buttons {"A", "B", "C"} default button "B"
set {theText, theButton} to {the text returned of the result,âŒ
the button returned of the result}
- è£è¶³ïŒâŒã«æ¹è¡ãæ¿å ¥ããŸãããæ¬æ¥ã¯ã²ãšã€ãªããã§ãã
âOne command in this example, "activate", requires comment. When TeXShop is asked to run an AppleScript, it calls a separate program to run the script. That program, Scriptrunner, is in the TeXShop bundle. Any dialogs created by the script will be displayed by Scriptrunner rather than by TeXShop. The "activate" command brings Scriptrunner to the front so dialogs will appear on top of other windows.
ãâ ããã®äŸã«ããã³ãã³ããactivateãã«ã¯è§£èª¬ãå¿ èŠã§ãã AppleScript ãå®è¡ããããèŠè«ããããšTeXShop ã¯ãå¥ã®ããã°ã©ã ãåŒã³åºããŠã¹ã¯ãªãããå®è¡ããŸãããã®ããã°ã©ã ââ Scriptrunner ã¯ã TeXShop ã«çµã¿èŸŒãŸããŠããŸããã¹ã¯ãªããã§äœæãããã€ã¢ãã°ã¯ãã¹ãŠã TeXShop ã§ã¯ãªã Scriptrunner ã§è¡šç€ºãããŸãã ãactivateãã³ãã³ã㯠Scriptrunner ãåé¢ã«æã£ãŠããã®ã§ããã€ã¢ãã°ã¯ä»ã®ãŠã€ã³ããŠãããæåã«è¡šç€ºãããŸãã
##Writing Scripts with TeXShop Typesetting CommandsïŒ TeXShop ã®ã¿ã€ãã»ããã»ã³ãã³ãã§ã¹ã¯ãªãããæžãïŒ
âIf a TeX project contains a bibliography, a sequence of typesetting commands must be run to update the bibliography. Latex is run first to create an .aux file. Bibtex is run to create .bbl and .blg files from this .aux file. Latex is run again to add the bibliography to the document. Latex is run a final time to update the references to the bibliography in the document.
ãâ ãTeX ãããžã§ã¯ããåèæç®ç®é²ãå«ãã§ããå Žåã«ã¯ãäžé£ã®ã¿ã€ãã»ããã»ã³ãã³ããå®è¡ããŠç®é²ãã¢ããããŒãããªããã°ãªããŸããããŸã LaTeX ãå®è¡ã㊠.aux ãã¡ã€ã«ãäœæããã BibTeX ãå®è¡ã㊠.aux ãã¡ã€ã«ãã .bbl ããã³ .blg ãã¡ã€ã«ãäœæãããå床 LaTeX ãå®è¡ããŠåèæç®ç®é²ãææžã«ä»ãå ããã LaTeX ãæçµçã«å®è¡ããŠç®é²ã«å¯Ÿããææžå ã®åç §ãã¢ããããŒãããã
âYour projects may contain similar sequences of typesetting commands. It is possible to use applescript to automate these sequences.
ãâ ãè€æ°ã®ãããžã§ã¯ãã«ãäžé£ã®åæ§ãªã¿ã€ãã»ããã»ã³ãã³ããå«ãŸããŠããããšãããã§ãããã AppleScript ã䜿ãã°ãããããäœæ¥ãèªååããããšãã§ããŸãã
âTo see how to do that we'll examine the OtherScripts->Bibliography command which comes with TeXShop. Here is the body of that command
ãâ ãã©ããªãµãã«ããã°ããã®ãã TeXShop ã«ä»å±ãããOtherScripts->Bibliographyããšããã³ãã³ããäŸã«èª¿ã¹ãŠã¿ãŸãããã®ã³ãã³ãã®æ¬äœã¯æ¬¡ã®ããã«ãªã£ãŠããŸãã
--Applescript
set fileName to #FILEPATH#
if fileName is equal to ""
activate
display dialog "Please save the file first" buttons {"OK"} default button "OK"
return
end if
set frontName to #DOCUMENTNAME#
tell application "TeXShop"
save document frontName
end tell
tell document frontName of application "TeXShop"
latexinteractive
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
bibtex
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
latex
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
latex
end tell
âThe first line of this command indicates that this is an AppleScript macro. The next lines check #FILEPATH#, a parameter which gives the full path to the tex source. This parameter is an empty string when a new document has been created and not yet saved. In that case the user is asked to save the document and the script ends.
ãâ ãã³ãã³ãã®ç¬¬ïŒè¡ç®ã¯ãããã AppleScript ãã¯ãã§ããããšã瀺ããŠããŸãã次ã®è¡ã§ã¯ #FILEPATH#ïŒ TeX ãœãŒã¹ã®ãã«ãã¹åãäžãããã©ã¡ãŒã¿ïŒããã§ãã¯ããŠããŸãããã®ãã©ã¡ãŒã¿ã¯ãæ°èŠæžé¡ãäœæãããŠããªãããŸã ä¿åãããŠããªããšã空ã£ãœã®æååã«ãªããŸãããã®å ŽåããŠãŒã¶ã¯ææžãä¿åããããã«èšãããã¹ã¯ãªããã¯çµäºããŸãã
âThe next line tells TeXShop to save the document. Notice that we use #DOCUMENTNAME# to refer to the document in question.
ãâ ã次ã«ã€ã¥ãè¡ã§ã¯ãææžãä¿åãããã TeXShop ã«åœããŠããŸãã察象ãšãªãææžãåç §ããã®ã« #DOCUMENTNAME# ã䜿ã£ãŠããããšã«æ³šæããŸãã
âThe remaining commands run latexinteractive, bibtex, latex, and latex. Recall that control returns to applescript immediately after calling a typesetting command before the typesetting job is over. The repeat loop tells the script to check whether the job is complete before running another typesetting task. The line "delay 2" causes applescript to pause rather than continually asking if the task is done and thereby slowing the entire computer down.
ãâ ãæ®ãã®ã³ãã³ã㧠latexinteractive, bibtex, latex, ããã« latex ãå®è¡ããŠããŸããã¿ã€ãã»ããã»ã³ãã³ããåŒã³åºããåŸãã¿ã€ãã»ããäœæ¥ãå®äºããåã«ãã³ã³ãããŒã«ã¯ããã« AppleScript ã«æ»ãããšãæãåºããŠãã ããã repeat ã®ã«ãŒãéšåã§ã¯ã次ã®ã¿ã€ãã»ããåŠçãå®è¡ãããåã«ãå ç«ã€äœæ¥ãå®äºãããã©ããããã§ãã¯ããããã¹ã¯ãªããã«åœããŠããŸãã ãdelay 2ããšããè¡ã¯ãäœæ¥ãå®äºãããã©ããã絶ããåãåããã€ã¥ããããšã§ã³ã³ãã¥ãŒã¿å šäœã®é床ãäœäžãããªããã AppleScript ã«éåããåãããŠããŸãã
##Writing Scripts with Shell CommandsïŒã·ã§ã«ã³ãã³ãã§ã¹ã¯ãªãããæžãïŒ
âWe will use the AppleScript "pdflatexc" by Claus Gerhardt to illustrate the principles involved in calling a Unix shell script from an Applescript. This particular shell script isn't very interesting; it adds the location of the teTeX binary files to the $PATH variable and calls pdflatex to typeset.
ãâ ãClaus Gerhardt ããã«ãã AppleScript ãpdflatexcãã䜿ã£ãŠã AppleScript ãã UNIX ã®ã·ã§ã«ã³ãã³ããåŒã³åºãåçãäŸç€ºããŠã¿ãŸãããããã®ã·ã§ã«ã¹ã¯ãªããèªäœã¯å€§ããŠããããããããŸãã ïŒ teTeX ã®ãã€ããªã®å Žæã $PATH å€æ°ã«å ãã pdflatex ãåŒã³åºããŠã¿ã€ãã»ãããè¡ãªã£ãŠããŸãã
âThe shell script itself is independent of TeXShop and can be run from the Terminal by typing "pdflatexc myfile.tex" provided the directory holding pdflatexc is in the search path for binaries. Here is that shell script:
ãâ ãã·ã§ã«ã¹ã¯ãªãããã®ãã®ã¯ã TeXShop ã«ã¯äŸåããŠããŸãããã pdflatexc ãå«ããã£ã¬ã¯ããªããã€ããªã®æ€çŽ¢ãã¹ã«ããã°ãpdflatexc myfile.texããšæã¡èŸŒãããšã§ Terminal ãããå®è¡ã§ããŸããããããã®ã·ã§ã«ã¹ã¯ãªããã§ãïŒ
#!/bin/tcsh
# pdflatexc
# Claus Gerhardt
#
# Usage
# pdflatexc filename.tex
set path= ($path /usr/local/teTeX/bin/powerpc-apple-darwin-current /usr/local/bin)
pdflatex --shell-escape "$1"
âOf course you are likely to write a more complicated script which performs several operations in sequence. That is when these techniques become useful.
ãâ ããã¡ãããããã€ãã®äœæ¥ã次ã ãšããªããŠãããããªãããè€éãªã¹ã¯ãªãããæžãããšãããã§ãããããããããšãã«ãããããããææ³ã圹ã«ç«ã€ããã«ãªããŸãã
âThe AppleScript used to call this shell script is more interesting. Here it is:
ãâ ããã®ã·ã§ã«ã¹ã¯ãªãããåŒã³åºãã®ã«äœ¿ã AppleScript ã¯ããã¡ãã£ãšããããããã®ã§ãããŸãã¯ã芧ãã ããïŒ
--Applescript
-- Apply only to an already saved file.
-- ãã§ã«ä¿åæžã¿ã®ãã¡ã€ã«ã«ã®ã¿é©çšããããšã
-- Claus Gerhardt, Nov. 2003
set scriptPath to (do shell script "dirname " & "~/Library/TeXShop/Scripts/ex")
set scriptPath to scriptPath & "/setname.scpt"
set scriptName to POSIX file scriptPath as alias
set scriptLiB to (load script scriptName)
tell scriptLib
set frontName to setname(#NAMEPATH#,#TEXPATH#)
end tell
set fileName to #TEXPATH#
set n to (number of characters of contents of fileName)
set fileNamequoted to quoted form of fileName
set baseName to do shell script "basename " & fileNamequoted
set m to (number of characters of contents of baseName)
set dirName to quoted form of (characters 1 thru (n - m - 1) of fileName as string)
set shellScript to "cd " & dirName & ";"
set shellScript to shellScript & "~/Library/TeXShop/bin/pdflatexc " & baseName
do shell script shellScript
tell document frontName
refreshpdf
end tell
âIgnoring the introductory comments, the first seven lines of this script are a magic recipe by Claus Gerhardt to save the source file and find the name of the document in question, setting "frontName" to this name. This recipe uses a compiled script named "setpath.scpt" in ~/Library/TeXShop/Scripts to do all the hard work. Careful reading shows that these lines find the path ~/Library/TeXShop/Scripts/setname.scpt and call this script with parameters #NAMEPATH# and #TEXPATH#.
ãâ ãå眮ãã®ã³ã¡ã³ãã¯ããŠããããã®ã¹ã¯ãªããã®åé ïŒè¡ã¯ã Claus Gerhardt ããã®éæ³ã®ã¬ã·ãã§ãââãœãŒã¹ãã¡ã€ã«ãä¿åããåŠçããããšããŠããææžã®ååãèŠã€ããŠãfrontNameãã«ã»ããããŠããŸãããã®ã¬ã·ãã§ã¯ã ~/Library/TeXShop/Scripts ã«ãããsetpath.scptããšããã³ã³ãã€ã«æžã¿ã®ã¹ã¯ãªããã䜿ã£ãŠããŒããªäœæ¥ãã¹ãŠãããªããŠããŸãã泚ææ·±ãèªã¿è§£ããŠã¿ãã°ããã®æ°è¡ã¯ ~/Library/TeXShop/Scripts/setname.scpt ãšãããã¹ãèŠã€ãããã©ã¡ãŒã¿ #NAMEPATH# ãš #TEXPATH# ã§ã¹ã¯ãªãããåŒã³åºããŠããããšãããããŸãã
âIn many AppleScripts all of this could be accomplished in an earier way using the commands:
ãâ ãå€ãã® AppleScript ã§ã¯ãããã¯ãã¹ãŠã次ã®ãããªã³ãã³ãã䜿ãç°¡åãªæ¹æ³ã§æžãŸããããŸãïŒ
set frontName to #DOCUMENTNAME#
tell document frontName of application "TeXShop"
save
end tell
âHowever, Gerhardt's script has two advantages. First, his script can be called when the front document is a log file, say /Users/koch/Examples/myfile.log, that is, in a case when the front document is not the document which should receive later commands. Second, if the file has never been saved, Gerhardt's script returns an error when trying to save, while the "save" command would cause TeXShop to hang after it put up a save dialog (see the help document Writing Scripts with TeXShop Typesetting Commands for details.)
ãâ ãããããªãã Gerhardt ããã®ã¹ã¯ãªããã«ã¯é·æãïŒã€ãããŸããã²ãšã€ã¯ãåé¢ã«ããææžããã°ãã¡ã€ã«ïŒããšãã° /Users/koch/Examples/myfile.log ã®ãããªãã®ïŒã§ãã£ãŠãââæèšããã°ããã以éã®ã³ãã³ããåãå ¥ããªããããªçš®é¡ã®ææžã ã£ããšããŠãââã¹ã¯ãªãããåŒã³åºããããšããããšã§ããããã²ãšã€ã¯ããã¡ã€ã«ãäžåºŠãä¿åãããŠããªãã£ãå Žåã Gerhardt ã®ã¹ã¯ãªããã¯ä¿åãè¡ãªãããšããŠãšã©ãŒãè¿ããŸãââãã®äžæ¹ã§ãä¿åãã³ãã³ãã«ãããä¿åãã€ã¢ãã°ãåºã㊠TeXShop ã¯ä¿çç¶æ ã«ãªããŸãïŒè©³ããã¯ãã«ãã®ãTeXShop ã®ã¿ã€ãã»ããã»ã³ãã³ãã§ã¹ã¯ãªãããæžãããåç §ããŠãã ããïŒã
âThe next six lines of the script define the variables dirName and baseName. If the source file is "/Users/koch/This directory/Stuff/myfile.tex", dirName is " '/Users/koch/This directory/Stuff' ", including the single and double quotation marks, and baseName is "myfile.tex." A lot of this work is required so spaces can occur in the names of folders. As always, tex does not allow spaces in the final file name.
ãâ ãã€ã¥ãïŒè¡ã§ã¯ãå€æ° dirName ãš baseName ãå®çŸ©ããŠããŸãããœãŒã¹ãã¡ã€ã«ãã/Users/koch/This directory/Stuff/myfile.texãã®å Žåã dirName ã¯ãã·ã³ã°ã«ã¯ãªãŒããšããã«ã¯ãªãŒããå«ããŠã" '/Users/koch/This directory/Stuff' "ããšãªãã baseName ã¯ãmyfile.texããšãªããŸãããã®äœæ¥éšåãå¿ èŠãªã®ã¯ããã©ã«ãåã«ã¹ããŒã¹ããã£ãŠãããããã«ã§ããäŸç¶ãšã㊠TeX ã¯ãæçµçãªãã¡ã€ã«åã«ããã¹ããŒã¹ã容èªããŸããã
âThe next three line call the shell script. The result is the same as typing "cd dirName; ~/Library/TeXShop/bin/pdflatexc baseName" in a Terminal, although, to be absolutely precise, dirName would have to be replaced by its unquoted form, i.e., if we use the example above, by '/Users/koch/This directory/Stuff' including the single quotes because of the space in the name of one directory.
ãâ ããã®ãŸã次ã®ïŒè¡ãã·ã§ã«ã¹ã¯ãªãããåŒã³åºããŠããŸããçµæçã«ã¯ Terminal ã§ãcd dirName; ~/Library/TeXShop/bin/pdflatexc baseNameããšæã¡èŸŒãã®ãšåããšã¯ãããã¯ããã«æ£ç¢ºã§ãââãšããã®ãã dirName ã¯åŒçšã§ã¯ãªã圢ïŒã€ãŸããäžã®äŸã§èšãã°ãéäžã®ãã£ã¬ã¯ããªã«ã¹ããŒã¹ãããã®ã§ã·ã³ã°ã«ã¯ãªãŒããå«ããŠã'/Users/koch/This directory/Stuff'ãïŒã«çœ®ãæããã°ãªããªãã®ã§ãã
âShell commands in AppleScript are issued in the form
ãâ ã AppleScript ã«ãããã·ã§ã«ã¹ã¯ãªããã¯æ¬¡ã®ãããªåœ¢ã§çºä»€ãããŸãââ
do shell script "cmd input"
âIf one wants to combine several shell scripts, it is better to write the command in an equivalent form
ãâ ãè€æ°ã®ã·ã§ã«ã¹ã¯ãªãããçµåããããã®ã§ããã°ã察çã«ã€ãªã圢åŒã§æžãã®ãããã§ãããââ
do shell script "cmd " & "input"
âNotice the space behind cmd and the quotes. The ampersand is a binary concatenation operator, i.e.,
ãâ ãcmd ãšåŒçšç¬Šã®éã®åè§ã¹ããŒã¹ã«æ³šæããŠãã ãããã¢ã³ããµã³ãïŒïŒèšå·ïŒã¯ãã€ããªã®é£çµæŒç®åã§ããã€ãŸãããããããšã§ãââ
"cmd " & "input" = "cmd input"
âWhen the shell is called via an applescript, the default working directory is the root directory. The command
ãâ ãã·ã§ã«ã AppleScript ã§åŒã³åºãããå Žåãããã©ã«ãã®äœæ¥ãã£ã¬ã¯ããªã¯ã«ãŒããã£ã¬ã¯ããªã§ãã
do shell script "cd " dirName
âchanges the directory to the directory specified in dirName; dirName is already quoted so that additional quotes are not needed.
ãâ ãäžã®ã³ãã³ãã§ã¯ããã£ã¬ã¯ããªã dirName ã§å®ããããŠãããã£ã¬ã¯ããªã«å€æŽããŠããŸã ïŒ dirName ã¯ãã§ã«åŒçšæžã¿ãªã®ã§åŒçšç¬Šãå ããå¿ èŠã¯ãããŸããã
âIf one would like to keep the working directory and issue further commands, then these commands may not be stated in the form "do shell script", since then a new shell would be invoked. In the terminal one would separate consecutive commands by semicolons, in AppleScript one does it by concatenating ";", i.e.,
ãâ ãäœæ¥ãã£ã¬ã¯ããªãåãããã«ããã«ã³ãã³ããå ¥ãããã®ã§ããã°ã ãdo shell scriptãã®åœ¢ã§ã¯èšè¿°ã§ããŸããââããã ãšæ°èŠã·ã§ã«ãåŒã³åºãããŠããŸããŸãã Terminal ã§ã¯é£ç¶ããã³ãã³ããã»ãã³ãã³ã§åºåããŸããã AppleScript ã§ã¯ã";"ãã䜿ããŸããã€ãŸããããããµãã«ââ
do shell script "cmd(1) " & "input(1)" & ";" & "cmd(2) " & "input(2)"
âThis is done in the above example: cmd(1) = cd, "input(1)" = dirName, cmd(2) = ~/Library/TeX/bin/pdflatexc - calling the shell script -, and "input(2)" = baseName.
ãâ ãäžèšã®äŸã§èšããªãããã¯ãããããããšã§ãïŒ cmd(1) = cd ã» "input(1)" = dirName ã» cmd(2) = ~/Library/TeX/bin/pdflatexcïŒã·ã§ã«ã¹ã¯ãªãããåŒã³åºããŠããŸãïŒ ã» "input(2)" = baseNameã
âThe lines
set shellScript to "cd " & dirName & ";"
set shellScript to shellScript & "~/Library/TeX/bin/pdflatexc " & baseName
âare simply a convenient way to concatenate this sequence of commands and input into one variable.
ãâ ãââãšããïŒè¡ã¯åã«ãã²ãšã€ãªããã®ã³ãã³ããå€æ°ããšã«åãã¡æžãããŠããã ãã®ããšã§ãã
âThe final three lines update the Preview window.
ãâ ãæåŸã®ïŒè¡ã§ãã¬ãã¥ãŒãŠã€ã³ããŠãæŽæ°ããŠããŸãã
âTo be sure, several of these lines are complicated, but these lines can be copied without change into new scripts.
ãâ ããããã«è€éãªè¡ãããã€ããããŸããããããããã®ã§ãããã®ãŸãŸã³ããŒããŠæ°ããã¹ã¯ãªããã«äœ¿ããŸãã