Skip to content

Tips And Tricks

sunderme edited this page May 31, 2023 · 13 revisions

This is a collection of useful tips and features for TeXstudio.

We encourage users to contribute and write down, what they deem interesting for others to know.

Dark mode

Dark mode support is currently worked on. The development version provides a set-up for syntax highlighting colors. Other schemes can be found here, here and here. The profiles to import should be changed from [formats] to [formatsDark].

Special comments

The editor TeXWorks introduced special LaTeX comments in the format % !TeX [command], which allow to pass information to the editor.

A subset of these commands is supported in TeXstudio. Currently these are:

% !TeX encoding = UTF-8 Tells TeXstudio which encoding to use for loading the file (Note: There is an automatic encoding detection in TeXstudio, which will work in many cases, but is not perfect. This command is only necessary, if automatic encoding detection fails for your files)

% !TeX spellcheck = en_GB TeXstudio will automatically load the specified dictionary for spell checking. This allows to easily work with files in different languages without the need to manually switch the spellchecker for every document.

Insert Graphic

The Insert Graphic wizard allows to conveniently insert images in your document by automatically generating all necessary code. You can also start the wizard by dragging % dropping images to TeXstudio. This works also for multiple files. Furthermore the wizard allows to edit existing graphics inclusion code. Just place the cursor on the code and start the wizard.

Fullscreen Mode

The fullscreen mode can also be started by double-clicking on an empty area on the menubar. This is in analogy to double-click on the window title bar, which maximizes the window in most window managers. Currently, this feature is only working for the main window. (In Ubuntu Unity, Alt-f, the letter not a function key, restores the menu bar allowing an exit from fullscreen mode).

Column Editing/Multiple Cursors

A cursor for simultaneous editing of multiple rows can be created by holding <Ctrl>+<Shift> and dragging the mouse. You can also create multiple cursor at arbitrary positions by holding <Ctrl>+<Alt> and clicking (not dragging) somewhere.

Without the mouse, you can use Ctrl+Alt and Up/Down arrows keys to place multicursors.

And for special use cases, there is Edit/Searching/Select All Matches, to create multi cursors after searching text with the search bar.

Edit/Selection/Select All Occurrences is like Edit/Searching/Select All Matches, but for the current word (the one where the cursor is currently placed) rather than the search. There are also commands Edit/Selection/Also Select Next|Prev Occurrence to create multiple cursors to the next|prev occurrence of the current word.

Tooltips and Context Menus

We are continuing to make TeXstudio more context aware. Look out for tooltips and context menus that give additional information and useful functionality in various places.

Add submenus to the toolbar

When configuring the toolbars at Options -> Configure -> Toolbars you can add complete submenus to the toolbar (e.g. the Tools -> Commands menu). Such a menu will appear as a dropdown list in the toolbar.

Using TXS with the multibib Package

TXS does not natively support multibib. However, you can make it work with the following settings.

Correct Recognition of the Commands in the Editor

  • Create a .cwl file in the [config directory](Frequently Asked Questions).

  • For every bibliography pub you create using the \newcites{pub}{Bibliography Title} command add the following four lines to the .cwl file:

    \citepub{%<bibid%>}#c
    \nocitepub{%<bibid%>}#c
    \bibliographypub{%<file%>}#b
    \bibliographystylepub{%<style%>}
    

    replacing pub for the actual used name. Go to TeXstudio Config -> Completion and check your created cwl file there.

Correct Compilation (platform independent)

  • Set the bibliography command to: bibtex ?*.aux

Correct Compilation (Windows)

  • (if the above does not work) create a file multibib.bat with the following content

    @ECHO off
    IF (%1)==() GOTO end
    
    FOR %%f in (%1\*.aux) DO bibtex %%f
    
    @ECHO on
    :end
    
  • Save multibib.bat to a reasonable place (e.g. the bin directory of your tex installation). This may be C:\Program Files\MiKTeX 2.9\miktex\bin or C:\texlive\2012\bin\win32. But any other place will also do.

  • Go to TeXstudio Config -> Command -> BibTeX and select the multibib.bat.

  • Now F11 will correctly compile the bibliography with multibib. Also, automatic bibliography update before the compilation will work.

Make TXS recognize user-defined citations and references

TXS automatically recognizes references and citations. This does not work out of the box if you define your own commands \newcommand{\myref}[1]{(see \ref{#1})} or \newcommand{\mycite}[1]{(see \cite{#1})}.

The following steps describe how you can announce your own commands to TXS.

  • Create a .cwl file in the config directory, e.g. usercommands.cwl. And add lines similar to

    \mycite{%<bibid%>}#c
    \myref{%<label%>}#r
    

    the c after # marks the command as a citation, likewise r marks it as reference.

  • Go to TeXstudio Config -> Commpletion and check your created cwl file there.

For more information on .cwl files see the corresponding section in the user manual.

Using a separate directory for auxiliary files

The auxiliary files created by LaTeX clutter their working directory. Aside from using Tools -> Clean Auxiliary Files for cleanup, you may want to have these files in a separate directory. This can be achieved in the following way:

  • Tell LaTeX engine (e.g., pdflatex) to store the auxiliary files in another location
    • In MiKTeX, you can modify the pdflatex command at Options -> Configure -> Commands, e.g., by adding -aux-directory=DIR. This option is MiKTeX only.
    • In TeX Live you have to use option -output-directory=DIR (MiKTeX has this option too), which makes pdflatex store not only auxiliary files but also the pdf file in specified location.
  • Tell TeXstudio to search for log (and probably pdf) files in the specified location
    • With -aux-directory=aux-files used, adding aux-files at Options -> Configure -> Build -> Build Options -> Additional Search Paths -> Log File (Advanced Options have to be enabled to configure this) does the work.
    • With -output-directory=aux-files used, both log and pdf files are stored in aux-files, hence you need to add aux-files to Additional Search Paths -> PDF File as well.
    • If there are multiple paths, use ; as separator in Windows, e.g., aux_dir;aux_dir2, otherwise (in Linux or macOS) use :.
  • Tell LaTeX utilities to read from and write to specified location
    • If you use bibtex, you have to modify the bibtex call to bibtex.exe -include-directory=aux-files aux-files.
    • Similar for biber, you can change it to biber.exe --output_directory=aux-files %.

Note: You have to create the directory aux-files yourself because pdflatex apparently exits with an error if the directory does not exist.

  • If you are using the external PDF viewer, go to the Commands settings screen and set External PDF viewer, so that it can find the PDF file, e.g.
xdg-open ?p{pdf}:ame > /dev/null

(this can vary depending on your external PDF viewer)

  • If you have a build script that generates any article images into your output directory and then your article includes the images from the output directory, then you probably want a recent version of texlive (after 2019-05-07) because older versions before 2019-05-07 have a bug which prevents it from searching for graphics in the output directory. For more details see this TeX Live bug

Alternatively if you have an older version of texlive you can use the following workaround in the preamble of your .tex file or in a custom .cls file (only needed if you use old texlive and include graphics from the output directory):

% Workaround a bug in the \includegraphics macro which fails to include images from the output directory
% For more details see
% https://github.com/latex3/latex2e/issues/145
\def\Gin@getbase#1{%
  \edef\Gin@tempa{%
    \def\noexpand\@tempa####1#1\space{%
      \def\noexpand\Gin@base{####1}}}%
  \@iffileonpath{\filename@area\filename@base#1}%
    {\Gin@tempa
     \expandafter\@tempa\@filef@und
     \edef\Gin@ext{#1}}{}}%

Inserting Citations from JabRef

In collaboration with the guys from JabRef, we implemented the possibility to directly insert citations from JabRef into TeXstudio (available since JabRef 2.9).

To insert a citation into TeXstudio

  • In the JabRef main interface, click on the drop down list (second to last icon) in the toolbar.
  • Select "TeXstudio".

Settings

The behavior can be configured in the plugin setting in JabRef. To open the settings, right-click on the TeXstudio icon in the drop down list in JabRef. The following settings are available:

  • Cite command: The TeX command for the citation (if you plan to use biblatex, you could replace the default \cite by \autocite). For OSX you have to set the full path here. In a standard installation this is /Applications/texstudio.app/Contents/MacOS/texstudio.
  • Path to TeXstudio: The location of the TeXstudio executable. Usually you don't have do modify this, since it is automatically determined in many cases. However, if inserting does not work, make sure this is correct.

If using biblatex: Back to JabRef main interface, go to Options → Preferences and:

  • if your .bib files are UTF-8 encoded, click on "General" and choose "UTF-8" in the "Default Encoding" drop down list,
  • click on "Advanced" button and check the "Biblatex mode" checkbox.

Usage

  • Open a .tex file in TeXstudio and a .bib file in JabRef.
  • Put the cursor in TeXstudio where you want to cite reference(s).
  • Switch to Jabref, select the reference(s) you want to cite and click on the TeXstudio plugin icon.
  • A \cite (or \autocite) command is inserted in TeXstudio and its mandatory argument contains the (list of) key(s) of the reference(s) you have selected.
  • If you place the cursor inside an already existing citation command, TeXstudio adapts and appends the selected citations instead of inserting a new command.

Spellchecking with multiple languages

TeXstudio only supports one dictionary per file for spellchecking. This is a limitation for documents with multiple languages, because all except the selected language are marked as errors. As a workaround, one can create a hybrid multi-language dictionary with HunspellMerge and use this one for spellchecking.

An alternative, is to just switch between multiple dictionaries, using the dictionary switch button in the statusbar.

Working with your own packages

  1. Make your .sty file known to the LaTeX distribution you are using. This step ensures that (pdf)latex knows your file an can use it when compiling. It is not TeXstudio specific and you can find detailed descriptions on the web (e.g. for MikTeX or for TeXlive. For TeXlive, you should texhash, because TXS uses the ls-R cache (see 2.). From now on compilation works fine. The issue is just that TXS may highlight the package name or commands as unknown.

  2. Package Names: TXS tries to obtain the information on installed packages from the distribution. With TeXlive, your package will be detected (make sure you have texhashed). For MikTeX, there's currenly no solution to detect packages in a local texmf directory, so you'll have to live with underlining missing package marker here. For details see Why does TXS mark a package as missing?.

  3. Commands: Read How does TXS know about valid commands. While TXS has some limited capability of auto-creating cwl files from sty files, we recommend to explcity write a cwl file and place it in according folder. When TXS finds an \usepackage{mypkg} command, it loads the corresponding mypkg.cwl and the commands defined therein will become known.

Setting paths when using the portable version

When using the portable version on a USB drive, paths (e.g. to a portable MikTeX installation on the same drive) may change because the USB drive might receive different drive letters on different computers.

To set up an always woking configuration, you can use paths relative to the texstudio executable [txs-app-dir] and the settings directory [txs-settings-dir]. For example you could use

[txs-app-dir]\..\MikTeX Portable\miktex\bin\x64\latex.exe

Using TeXstudio for PDF presentations

TeXstudio has advanced presentation features to show a presentation on one screen and additional information (like remaining time or following slides) on a second screen that is hidden from the audience.

  • Switch to the windowed internal viewer and use Window / New Window to create two PDF viewer windows

  • Enable Configure / Synchronize multiple views on both windows

  • Disable View / Continuous on both windows, so no partial pages are shown

  • On the window for the presenter choose View / Grid / 1x1, so only one page is shown, move it to the presenter screen and choose View / Presentation

  • On the window for your own screen, choose which additional information to show:

    • To show the current and next slides, choose View / Grid / 2x1 and View / Grid / Single Page Step
    • To show the remaining time, choose Window / Show / Clock and set the time with a right click on the colored bottom bar

Log files created from previews

A preview creates temporary files. You can browse these files by navigating to the folder for temporary files. TeXstudio supports loading .log files. Thus you better work with the .log file as described above. Just copy the file name without extension from the messages panel to the clipboard, select File/Open..., then navigate to the folder for temporary files and use the clipboard for entering the log file name (don't forget to add file extension .log). After you have confirmed loading the file switch to the log panel in the messages pane. %tmp% may be used as a shortcut for the folder for temporary files (depending on OS used).

Message Preview process started

Select temporary log file