Skip to content

Tips And Tricks

MeanSquaredError edited this page Apr 6, 2020 · 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 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

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

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 there 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 pdflatex to store the auxiliary files in another location using the option -aux-directory=DIR: For this you modify the pdflatex command at Options -> Configure -> Commands, e.g. by adding -aux-directory=aux-files.
  • Tell TXS to search for log files in this location by adding ./aux-files at Options -> Configure -> Build -> Build Options -> Additional Search Paths -> Log (Advanced Options have to be enabled to configure this).
  • 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.

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 a separate output directory

If you want TeXstudio to keep all of the output files in a separate output directory you can achieve that by setting a few configuration options. Assuming that you use TeX Live and you want to set /home/john/texout as your output directory you need to do the following:

  • Open Options / Configure TeXstudio... and enable Show Advanced Options (lower left corner of the configuration popup window).

  • Go to Build settings and set Default Compiler as

pdflatex -synctex=1 -interaction=nonstopmode -output-directory=/home/john/texout %.tex (the important part here is -output-directory)

  • On the same Build screen add /home/john/texout to the directory lists in Additional Search Paths / Log File Additional Search Paths / PDF File

  • 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}}{}}%

Clone this wiki locally