4

As I wrote in this answer to my question, I decided to use a shell script in order to concatenate the bunch of .tex files and compile them. However, this way, when ever I want to compile the whole glossary, I have to switch to the terminal and run the script there, from the right directory, i.e. the glossary's directory.

I'm using TeXShop on a mac OSX, and I want to know is there a way to set a short cut in TeXShop that will invoke the script?

Thanks, Dror.

Dror
  • 22,613

2 Answers2

6

Running this sort of thing is probably better done using TeXShop's "engines" instead of calling an applescript from the Macro Editor.

If you look in your ~/Library/TeXShop/Engines folder (especially the Inactive folder) you can see various examples of such engines. The engine files themselves are just shell scripts (so they need to have the executable bit set) Once you've got the script working you can put it in the Engines folder and it will appear in the pulldown menu beside the Typeset button on any document window.

It's very possible that the script you want to run already exists (you mention glossaries). Have your looked at the LaTeXmk engine for TeXShop?

The LaTeXmk script (various versions are found in the Inactive folder; just drag them to the Engines folder and restart TeXShop to activate them.) runs all of the required numbers of latex/bibtex/mkindex/makeglossaries etc. so that everything in your document is complete. It knows about most of the major packages' extra .aux-type files, and is quite smart. The LaTeXmk engine is maintained by Herb Schulz and the latest version can be obtained from his web page.

One thing to watch out for when running scripts from within an application is that the path and environment variables set inside the application are not identical to the path and environment variables you may have set in you bash .profile or csh .cshrc file.

Alan Munn
  • 218,180
  • Does it make sense to do this even though my script is very much specialized to my task? Anyway, copying the bash script to the engines directory and adding the right cd at the beginning does work as expected. Adding % !TEX TS-program = glossary to each entry/file, where glossary.engine is the new engine, makes the process even quicker. One problem though: how can I tell the engine to open the generated pdf file after the process is over? – Dror Feb 02 '11 at 07:58
  • @Dror Whether it makes sense I guess depends on how often you will be doing it, I guess. As for opening the pdf you could try adding open -a TeXShop glossaries.tex at then end of the script, which should open both the source and pdf. (If you just want the pdf then open the .pdf version of the filename.) – Alan Munn Feb 02 '11 at 14:31
6

Look in the TeXShop Macro Editor—you'll see it can be used for code snippets or scripts. The first item in the Macro menu is "AppleScripts," where you can see some examples, including some that just wrap around a shell script or command. So something like this should work:

--AppleScript
-- #FILEPATH# in the text will be replaced by the path of the document

do shell script "cd #FILEPATH# && source generateGlossary.sh"

The first line tells TeXShop that this macro should be run as a script. The second line is just an AppleScript comment. The third line does the work.

Macros can be bound to command key combinations as well.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • Thanks for the tip! However, I'm afraid, something doesn't work for me. Should I have do shell script "cd ~/path && ./generateGlossary.sh" or do shell script "cd ~/path && generateGlossary.sh" either case it doesn't seems to work. Any idea? – Dror Nov 30 '10 at 14:54
  • Try my edited version. Could be a permissions thing since TeXShop runs in a new environment. – Matthew Leingang Nov 30 '10 at 15:15
  • I tried with this source option, but now, although it doesn't produce errors, nothing happens. I don't know even how to check if the script was invoked. I tried to have touch text.txt instead of the script call, and it did produced a file in the right directory. – Dror Nov 30 '10 at 15:31
  • Is the program you're trying to run an actual shell script? If so, you could replace "source" with the shell name...I think. – Matthew Leingang Nov 30 '10 at 15:46
  • I tried to generate an applescript with the line from above, and run it. It runs, and calls my script. The problem is that the script returns an error. If I run the script directly from the terminal, it runs smoothly. I find it strange. Is there some other tip? – Dror Nov 30 '10 at 16:37
  • Not without knowing what the error is :-D – Matthew Leingang Nov 30 '10 at 16:44
  • The error is returned by my script, and it means that the script failed in the first run of pdflatex. Therefore, it doesn't go on to the next one. I have just verified, using a standalone script, and all the prior calls in the script returns 0. It just fails to run the pdflatex. – Dror Nov 30 '10 at 16:56
  • replace the macro text do shell script... to set output to do shell script ..., then return output. I think then you'll get to see your error and you can diagnose it. – Matthew Leingang Nov 30 '10 at 16:57
  • This indeed enabled me to see the output more easily. But, I still get the same error, namely, that the first run of pdflatex failed. It somehow doesn't run pdflatex properly. – Dror Nov 30 '10 at 17:06
  • Does "doesn't run properly" mean "doesn't run (at all)" or "runs, but does something weird." If it doesn't run at all, perhaps specify the full path to pdflatex. – Matthew Leingang Nov 30 '10 at 19:00
  • Well, I'm pretty sure that it ran pdflatex yesterday. Today I had some problems with that. However, adding /usr/texbin before all the calls to pdflatex and bibtex solved the problem! Thanks a lot. Now I can hit CMD+5 and compile my glossary. Thanks. – Dror Dec 01 '10 at 08:22
  • That makes sense. Whatever environment the script is run in does not have /usr/texbin in its search path (as opposed to your user environment, which probably does). This comment thread should serve as a future reminder (to myself) to check out the chat feature. – Matthew Leingang Dec 01 '10 at 13:07
  • @Matthew Although shell scripts can be run via applescript through the Macros procedure, for the questioner's purposes the TeXShop Engines route is probably a better choice. – Alan Munn Feb 01 '11 at 16:13
  • @Alan: Now that you mention it, I think I agree with you. – Matthew Leingang Feb 01 '11 at 19:55