Latex magic comments

It can be a real pain to open files with various character encodings inside TeXShop. Indeed, you basically have to change TeXShop’s settings each time.

Hopefully, I recently came across a little-documented feature that allows you to specify the encoding on a per-file basis: you simply add a metadata (a special TeX comment) at the top of the file to set the encoding, and TeXShop will load and save it accordingly. Use:

%!TEX encoding = IsoLatin

for ISO-8859-1 (Latin 1), or:

%!TEX encoding = UTF-8 Unicode

for UTF-8. Be sure to type exactly that, as TeXShop is case-sensitively picky!

Note: magic comments (or magic markers) alter TeXShop’s default behavior on a per-file basis. These are basically regular TeX comments, but they start with %!, thus they are interpreted by TeXShop if they appear at the top of a file.

Set the character encoding:

%!TEX encoding = UTF-8 Unicode
%!TEX encoding = IsoLatin

Set the engine (command to be run with the Typeset command, ⌘T):

%!TEX TS-program = context

Set the name of the “main”/“root” file, the one on which to call the typesetting command:

%!TEX root = main_file_of_my_phd.tex

Set the language to be used by the spell-checker:

%!TEX spellcheck = de-DE

When using source/PDF synchronization with multiple files, TeXShop is able to spot \include and \input commands in the main file. However this does not work with ConTeXt, so the following command allows one to explicitly reference an included file vis-à-vis TeXShop. Therefore it may be used several times:

%!TEX projectfile = chapter1.tex
%!TEX projectfile = chapter2.tex

Source: http://www.jacquet80.eu/blog/tag/LaTeX

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.