5

Going further: Other tools

5.1 SyncTeX’ing between source and preview

When you are reading a document in the preview window and see something to change, it is convenient to go immediately to the corresponding place in the source. To do so, hold down Ctrl (Mac OS X: pict) and click at the appropriate place in the preview; the cursor will move and highlight the corresponding location in the source window. The same is true in the other direction: Ctrl pict in the source will highlight the same line in the preview window.1

Here a remark for users under Windows: this only works if all the names for folders/files/…do not have accented characters. If, for example, your document is in C:\Documents and Settings\Propriétaire\My Documents\thesis it will not work because of the é in Propriétaire!

5.2 Special comment strings

Special comments, at the very beginning of the files, can be used to manage two other aspects of the compilation.

By default, TEXworks uses the “utf-8” encoding for loading and saving files, but some files could be saved in another encoding. Common ones are “latin1”, which is the dominant encoding on Windows when using western languages, and “Apple Roman” which is dominant on Mac OS.

To set a different encoding for a specific file one can put the following at the beginning of that file:

  % !TeX encoding = latin1

Note that without this line, you must tell TEXworks the correct encoding manually. Otherwise, your data could be corrupted! To override TEXworks’s default choice of encoding, use the menu that appears when you click on the editor window’s middle status bar widget.

If you opened a file in TEXworks that was not saved as utf-8 but is lacking the % !TeX encoding line, it might be displayed with (some) weird characters. In that case, you can specify the correct encoding via the status bar widget menu in the same way, but it is imperative that you then use Reload using selected encoding from the same menu! This forces TEXworks to open the document again with the encoding you selected, the weird characters should be replaced by normal ones, and only then it is safe to continue to work normally. To avoid having to repeat this procedure each time you open this file, you should either switch to utf-8 for saving it in the future or add a proper % !TeX encoding line.

If we want to compile a file with another programme than the default TEX or LATEX, we put at the beginning of the file:

  % !TeX program = <the_programme>

for example:

  % !TeX program = xelatex

Pay attention to this last instruction. You have to use the name of the programme here which should be used for the whole project, as the first encountered programme when starting typesetting is used (which is the one from the sub-document you are in). TEXworks will use that programme, even if another name appears in the main document!

When opening a document which contains a % !TeX program line, the specified programme will become the one to use and its name will appear in the drop down menu in the toolbar; you can, however, override this by selecting a different one from the drop down list, if you want.

In addition, you can set the spell checking language by a similar comment line:

  % !TeX spellcheck = <language_code>

The language codes available on your system are listed in parentheses in Edit Spelling next to the human-readable name of the language.

5.3 Formatting the source for legibility

To facilitate legibility of the source, one can use indentation as programmers do:

  \begin{itemize}
      \item First element of the list;
      \item second element;
      \item last element:
      \begin{itemize}      % beginning of a sub-list
          \item first sub-element;
          \item second sub-element.
      \end{itemize}
  \end{itemize}

This increases legibility, but works well only on short lines, without text wrapping; or if one chooses not to use text wrapping by unchecking Format Wrap lines.

The command FormatIndent or the shortcut Ctrl] (Mac OS X: pict]) will indent the line, or the selected lines, by inserting a tab character. You can repeat the process to increase the indent.

To remove one level of indentation, use FormatUnindent or the shortcut Ctrl[ ( pict[ on Mac OS X).2

As indent only indents the first part of very long (wrapped) lines, this is not very satisfactory in some cases. But one can ask TEXworks to split a long line (longer than the width of the editing window) into short ones adding a hard coded line feed. FormatHard Wrap... opens a dialog box in which you can specify the width of the lines; you can also re-format lines which have already been split.

5.4 Showing the tags

When a document is becoming long and you want to move to a specific place (a chapter, a section, a subsection, …) you normally need to scroll the editing window to find the desired location, or use the Find dialog if you remember a keyword in the chapter’s title.

To the same end, though a lot more comfortable, you can also use the structural information in the document to navigate the source: the menu item WindowShowTags opens a panel showing the information detected by TEXworks. Clicking on an item in the panel moves the cursor to the corresponding part in the source. That panel, like any other, can be resized by dragging its border.

The same action is possible in the PDF window from WindowShowTable of contents, but this only works if one has created structure tags in the PDF file using the package hyperref.

5.5 Organising the windows

By default, the editor/source window opens on the left and the preview one on the right (when the corresponding PDF file exists), thus splitting the screen in two.

You can change the position of the windows in the Window menu. Stack and Side by side give the default effect if there is only one document open. If not, Stack creates a mosaic with all the windows. The other options allow to place the windows for your convenience. It is also always possible to resize and move the windows manually, of course.

For the preview you can change the way it is presented and of course the zoom by ViewActual size, Fit to width and Fit to window; you can also zoom in and out. Shortcuts exist for all these actions and are shown next to the menu items.

5.6 Cleaning the working folder

Very soon when one uses (LA)TEX, one discovers that the working folder is cluttered by many files which have the name of the source file but different extensions: .aux, .log, .toc, .lof, .lot, .bbl, …

All these are files needed by (LA)TEX to be able to create the table of contents, lists of figures/tables, the bibliography, the cross references and, also very importantly, to keep track of what it did (in the .log file).

Apart from the external files, images, pictures, …, the only files required are the .tex files, the sources of the document. One can erase all the others. Sometimes, this is even necessary when (LA)TEX gets stuck after an error.

This can be done using a TEXworks command from the File menu with the Remove Aux files… item.

When you use this command, a dialog box opens in which you can check/uncheck the files you want to remove.3 The dialog box will only list files that actually exist in the folder; if you removed all these auxiliary files before, you get a message box saying that there is no file to remove at the moment.

The list of auxiliary files which are taken into account is defined in the file texworks-config.txt in the configuration folder of the TEXworks resources folder. You could add some if required.

5.7 Changing the configuration

We have seen in section 2 (on page 11 ) that the first time you use TEXworks, it creates a resource folder and also that it saves default preferences.

It is possible to define a personal place where one wants the resource folder and the preferences. This can be handy when one wants a portable system (e.g., on an USB stick) or when one wants to easily access the templates or completion folders for modifications.

For this, create a file texworks-setup.ini in the programme folder in which you specify the path to the folder containing the completion, configuration, dictionaries,…folders and the configuration file (texworks.ini); there will be two lines:

  inipath=C:/myfolder/TW_conf/
  libpath=C:/myfolder/TW_conf/

inipath for the configuration file and libpath for the necessary folders. Here, TW_conf would replace the resource folder TeXworks. Note that the referenced folder (here TW_conf) should exist—it will not be created—, and that the / is used even on Windows (instead of the common \).

If one wants to put the resource folder in the programme folder as a subfolder, one can use an instruction like inipath=./TW_conf/; all relative paths are taken to be relative to the TEXworks programme folder (on Mac OS X, the folder containing the app package is used).

One can also add a line like

  defaultbinpaths=C:/Program Files/MiKTeX 2.7/miktex/bin

to specify where the programmes of the TEX distribution are located; but this instruction is not yet completely operational, especially under Windows.