diff --git a/LaTeXTools.sublime-settings b/LaTeXTools.sublime-settings index 71c2cca24..3e4e2733c 100644 --- a/LaTeXTools.sublime-settings +++ b/LaTeXTools.sublime-settings @@ -213,7 +213,12 @@ "osx": { // Path used when invoking tex & friends; MUST include $PATH - "texpath" : "$PATH:/Library/TeX/texbin:/usr/texbin:/usr/local/bin:/opt/local/bin" + // For TeXlive 2011 (or other years) use + "texpath" : "$PATH:/Library/TeX/texbin:/usr/texbin:/usr/local/bin:/opt/local/bin", + // For MiKTeX + // "texpath" : "$PATH:/usr/local/bin:$HOME/bin", + // TeX distro: "miktex" or "texlive" + "distro" : "texlive" }, @@ -237,7 +242,12 @@ "linux" : { // Path used when invoking tex & friends; MUST include $PATH + // For TeXlive 2011 (or other years) use "texpath" : "$PATH:/usr/texbin", + // For MiKTeX + // "texpath" : "$PATH:/usr/local/bin:$HOME/bin", + // TeX distro: "miktex" or "texlive" + "distro" : "texlive", // Command to invoke Python. Useful if you have Python installed in a // non-standard location or want to use a particular version of python. // Both Python2 and Python3 are supported, but must have the DBus bindings @@ -379,7 +389,8 @@ // people writing their own build engines. // // "traditional" replicates the 'old' system based on - // latexmk (TeXLive) / texify (MiKTeX) + // latexmk (TeXLive, MiKTeX) / texify + // (MiKTeX, missing `Perl` interpreter and `latexmk` MiKTeX package) // // custom name you can also use third-party build engines; // if so, set the "builder_path" option below @@ -640,4 +651,4 @@ If you use `infinite` the cache will not invalidated automatically. */ "local_cache_life_span": "30 m" -} \ No newline at end of file +} diff --git a/README.markdown b/README.markdown index 34a3ac9c7..9b194b172 100755 --- a/README.markdown +++ b/README.markdown @@ -36,7 +36,7 @@ If you also use prereleases of other packages just add them comma separated into This plugin provides several features that simplify working with LaTeX files: -* The ST build command takes care of compiling your LaTeX source to PDF using `texify` (Windows/MikTeX) or `latexmk` (OSX/MacTeX, Windows/TeXlive, Linux/TeXlive). Then, it parses the log file and lists errors and warning. Finally, it launches the PDF viewer and, on supported viewers ([Sumatra PDF](http://sumatrapdfreader.org/free-pdf-reader.html) on Windows, [Skim](http://skim-app.sourceforge.net/) on OSX, and [Evince](https://wiki.gnome.org/Apps/Evince) on Linux by default) jumps to the current cursor position. +* The ST build command takes care of compiling your LaTeX source to PDF using `texify` (MikTeX when the `Perl` interpreter and the `latexmk` MiKTeX package are missing) or `latexmk` (OSX/MacTeX, Windows/TeXlive, Linux/TeXlive). Then, it parses the log file and lists errors and warning. Finally, it launches the PDF viewer and, on supported viewers ([Sumatra PDF](http://sumatrapdfreader.org/free-pdf-reader.html) on Windows, [Skim](http://skim-app.sourceforge.net/) on OSX, and [Evince](https://wiki.gnome.org/Apps/Evince) on Linux by default) jumps to the current cursor position. * Forward and inverse search with the named PDF previewers is fully supported * Fill everything including references, citations, packages, graphics, figures, etc. * Plugs into the "Goto anything" facility to make jumping to any section or label in your LaTeX file(s) diff --git a/builders/traditionalBuilder.py b/builders/traditionalBuilder.py index a546b6a09..d8f2386df 100644 --- a/builders/traditionalBuilder.py +++ b/builders/traditionalBuilder.py @@ -12,12 +12,15 @@ from pdfBuilder import PdfBuilder import shlex +from latextools_utils.perl_latexmk_installed import perl_latexmk_installed +from latextools_utils.distro_utils import using_miktex + DEBUG = False DEFAULT_COMMAND_LATEXMK = ["latexmk", "-cd", "-f", "-%E", "-interaction=nonstopmode", "-synctex=1"] -DEFAULT_COMMAND_WINDOWS_MIKTEX = ["texify", "-b", "-p", "--engine=%E", +DEFAULT_COMMAND_MIKTEX_TEXIFY = ["texify", "-b", "-p", "--engine=%E", "--tex-option=\"--synctex=1\""] @@ -36,17 +39,13 @@ def __init__(self, *args): self.name = "Traditional Builder" # Display output? self.display_log = self.builder_settings.get("display_log", False) + # Build command, with reasonable defaults - plat = sublime.platform() - # Figure out which distro we are using - distro = self.platform_settings.get( - "distro", - "miktex" if plat == "windows" else "texlive" - ) - if distro in ["miktex", ""]: - default_command = DEFAULT_COMMAND_WINDOWS_MIKTEX - else: # osx, linux, windows/texlive, everything else really! - default_command = DEFAULT_COMMAND_LATEXMK + # osx, linux, windows everything else really! + default_command = DEFAULT_COMMAND_LATEXMK + # When MiKTeX missing perl and latexmk, the `texify` compiler driver will be used. + if using_miktex() and not perl_latexmk_installed(): + default_command = DEFAULT_COMMAND_MIKTEX_TEXIFY self.cmd = self.builder_settings.get("command", default_command) if isinstance(self.cmd, strbase): @@ -136,8 +135,8 @@ def commands(self): self.display("done.\n") - # This is for debugging purposes + # This is for debugging purposes if self.display_log: self.display("\nCommand results:\n") self.display(self.out) - self.display("\n\n") + self.display("\n\n") diff --git a/docs/available-builders.md b/docs/available-builders.md index 2a8f54684..30c72df7d 100644 --- a/docs/available-builders.md +++ b/docs/available-builders.md @@ -4,7 +4,7 @@ By default, LaTeXTools uses the `traditional` builder, which is designed to work in most circumstances and for most setups. This builder provides all of the builder features discussed elsewhere in the documentation, such as the various [builder features](features.md#default-builder), including multi-document support, the ability to set LaTeX flags via the `TeX Options` settings, etc. -When you are using MiKTeX, the `traditional` builder defaults to using the MiKTeX compiler driver [`texify`](http://docs.miktex.org/manual/texifying.html), which automatically runs PDFLaTeX / XeLaTeX / LuaLaTeX as many times as necessary to generate a document. Note that because of certain limitations of `texify`, some features, such as support for output directory, auxiliary directory, jobname, etc. are unavailable when using the traditional builder. You can change this by installing `latexmk` and changing the `command` setting in the `builder_settings` block to `"latexmk -cd -f -%E -interaction=nonstopmode -synctex=1"`, in which case the `traditional` builder will run `latexmk` instead of `texify` +When you are using MiKTeX and are missing `Perl` interpreter and the `latexmk` MiKTeX package, the `traditional` builder defaults to using the MiKTeX compiler driver [`texify`](http://docs.miktex.org/manual/texifying.html), which automatically runs PDFLaTeX / XeLaTeX / LuaLaTeX as many times as necessary to generate a document. Note that because of certain limitations of `texify`, some features, such as support for output directory, auxiliary directory, jobname, etc. are unavailable when using the traditional builder. You can change this by installing `latexmk` MiKTeX package and a `Perl` interpreter, in which case the `traditional` builder will run `latexmk` instead of `texify`. When you are using any other setup (MacTeX or TeXLive on Linux or Windows), the `traditional` builder uses [`latexmk`](http://www.ctan.org/pkg/latexmk/), which supports all the documented features for the builder. diff --git a/docs/features.md b/docs/features.md index 003033a8c..03903a3a1 100644 --- a/docs/features.md +++ b/docs/features.md @@ -94,7 +94,7 @@ There are three special values that can be used, `<>` `<>` and `< **Note**: the `--aux-directory` flag is only implemented by MiKTeX, so the corresponding settings will only be valid if you are using MiKTeX, as indicated by your `distro` setting. To get similar behavior on TeXLive / MacTeX, you can use the `copy_output_on_build` setting described in the [settings section](settings.md#output-directory-settings) with any of the `output_directory` settings. This will run `pdflatex` / `xelatex` / `lualatex` with the `--output-directory` flag and then copy the resulting PDF to the same directory as your main TeX document. -**Note**: These flags can only be set when using `latexmk` (i.e., the `traditional` builder on OS X and Linux), the `basic` builder or the `script` builder (see below [for documentation on using the script builder](available-builders.md#script-builder)). If you are using `texify` (i.e. the `traditional` builder on MiKTeX) or the simple builder, the `output_directory` and `aux_directory` settings will be ignored. +**Note**: These flags can only be set when using `latexmk` (i.e., the `traditional` builder on Windows, OS X and Linux), the `basic` builder or the `script` builder (see below [for documentation on using the script builder](available-builders.md#script-builder)). If you are using `texify` (i.e. the `traditional` builder on MiKTeX) or the simple builder, the `output_directory` and `aux_directory` settings will be ignored. ### Jobname The `--jobname` flag can be set in several ways: @@ -102,7 +102,7 @@ The `--jobname` flag can be set in several ways: * Using the [TeX Options](#tex-options) feature to set `--jobname` * Using the corresponding `jobname` setting detailed in [the settings section](settings.md#output-directory-settings). -**Note**: Jobname can only be set when using `latexmk` (i.e., the `traditional` builder on OS X and Linux), the `basic` builder or the `script` builder (see below [for documentation on using the script builder](available-builders.md#script-builder)). If you are using `texify` (i.e. the `traditional` builder on MiKTeX) or the simple builder, the `jobname` setting wil be ignored. +**Note**: Jobname can only be set when using `latexmk` (i.e., the `traditional` builder on Windows, OS X and Linux), the `basic` builder or the `script` builder (see below [for documentation on using the script builder](available-builders.md#script-builder)). If you are using `texify` (i.e. the `traditional` builder on MiKTeX) or the simple builder, the `jobname` setting wil be ignored. ### Customizing the compilation command It is possible to customize the command run by setting the `command` option under Builder Settings. See the section on [Builder Settings](settings.md#builder-settings) for details. diff --git a/docs/index.md b/docs/index.md index 45e1fc851..a752c075a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,7 +4,7 @@ LaTeXTools plugin provides several features that simplify working with LaTeX files: -* The ST build command takes care of compiling your LaTeX source to PDF using `texify` (Windows/MikTeX) or `latexmk` (OSX/MacTeX, Windows/TeXlive, Linux/TeXlive). Then, it parses the log file and lists errors and warning. Finally, it launches the PDF viewer and, on supported viewers ([Sumatra PDF](http://sumatrapdfreader.org/free-pdf-reader.html) on Windows, [Skim](http://skim-app.sourceforge.net/) on OSX, and [Evince](https://wiki.gnome.org/Apps/Evince) on Linux by default) jumps to the current cursor position. +* The ST build command takes care of compiling your LaTeX source to PDF using `texify` (MikTeX when the `Perl` interpreter and the `latexmk` MiKTeX package are missing) or `latexmk` (OSX/MacTeX, Windows/TeXlive, Linux/TeXlive). Then, it parses the log file and lists errors and warning. Finally, it launches the PDF viewer and, on supported viewers ([Sumatra PDF](http://sumatrapdfreader.org/free-pdf-reader.html) on Windows, [Skim](http://skim-app.sourceforge.net/) on OSX, and [Evince](https://wiki.gnome.org/Apps/Evince) on Linux by default) jumps to the current cursor position. * Forward and inverse search with the named PDF previewers is fully supported * Fill everything including references, citations, packages, graphics, figures, etc. * Plugs into the "Goto anything" facility to make jumping to any section or label in your LaTeX file(s) diff --git a/docs/install.md b/docs/install.md index 6c1c75a88..c2c39cfa4 100644 --- a/docs/install.md +++ b/docs/install.md @@ -18,9 +18,16 @@ If you are running LaTeXTools for the first time, you may want to run the **LaTe ### Distribution -On **OSX**, you need to be running the [MacTeX](https://www.tug.org/mactex/) distribution (which is pretty much the only one available on the Mac anyway). Just download and install it in the usual way. We have tested MacTeX versions 2010--2016, both 32 and 64 bits; these work fine. MacTeX 2008 does *not* seem to work out of the box, so please upgrade. +On **OSX**, both [MacTeX](https://www.tug.org/mactex/) and [MiKTeX](http://www.miktex.org/) (since version 2.9.6300) are supported. Pick one and install it following the relevant documentation. We have tested MacTeX versions 2010--2016, both 32 and 64 bits; these work fine. MacTeX 2008 does *not* seem to work out of the box, so please upgrade. The MiKTeX has recommended to install the latest version. + +- MacTeX + If you don't want to install the entire MacTeX distribution—which is pretty big—[BasicTeX](https://www.tug.org/mactex/morepackages.html) will also work, though you may need to spend more time ensuring all the packages you need are installed! One such package that is missing is `latexmk`, which is a script for building LaTeX documents, which LaTeXTools uses by default. You can either choose to install `latexmk` or [change the builder](#builder.md) to use a builder that does not require `latexmk`. To install `latexmk`, you can either use the **TeX Live Utility** (assuming you are using a recent version of BasicTeX) or from the **Terminal** type `sudo tlmgr install latexmk`, which will prompt you for your password and install the `latexmk` package. + +- MiKTeX + MiKTeX adopts a rolling update mechanism to always keep up-to-date, and based on the on-the-fly package management mechanism, it asks users if they want to automatically install missing components from the Internet, if required. This allows you to reduce TeX installations as much as possible. + + We recommend following the [official guidelines](https://miktex.org/howto/install-miktex-mac) for installation and update, and turn on the auto-install feature. One such package that is missing is `latexmk`, which is a script for building LaTeX documents, which LaTeXTools uses by default. You can either choose to install `latexmk` or [change the builder](#builder.md) to use a builder that does not require `latexmk`. To install `latexmk`, you can either use the **MiKTeX Console** or from the **Terminal** type `sudo mpm --admin --install latexmk` or `mpm --install latexmk`, which will prompt you for your password and install the `latexmk` package. -If you don't want to install the entire MacTeX distribution—which is pretty big—[BasicTeX](https://www.tug.org/mactex/morepackages.html) will also work, though you may need to spend more time ensuring all the packages you need are installed! One such package that is missing is `latexmk`, which is a script for building LaTeX documents, which LaTeXTools uses by default. You can either choose to install `latexmk` or [change the builder](#builder.md) to use a builder that does not require `latexmk`. To install `latexmk`, you can either use the **TeX Live Utility** (assuming you are using a recent version of BasicTeX) or from the **Terminal** type `sudo tlmgr install latexmk`, which will prompt you for your password and install the `latexmk` package. ### Setup Skim @@ -77,7 +84,16 @@ Sorry for the complications. It's not my fault. ### Distribution -On **Windows**, both [MiKTeX](http://www.miktex.org/) and [TeXLive](https://www.tug.org/texlive/) are supported. Pick one and install it following the relevant documentation. +On **Windows**, both [MiKTeX](http://miktex.org/) and [TeXLive](https://www.tug.org/texlive/) are supported. Pick one and install it following the relevant documentation. + +### Setup Perl + +If you are using `latexmk` with MiKTeX, you will need to install both the `latexmk` MiKTeX package and a `Perl` interpreter. We recommend the following Perl distributions: + +- [Strawberry Perl](http://strawberryperl.com/) +- [ActiveState Perl](http://www.activestate.com/activeperl/downloads) + +First of all, download and install a Perl distribution. Then start the **MiKTeX Console**, and install the `latexmk` package. Make sure the Perl binaries added to your `PATH` system variable or to the `texpath` when setting up LaTeXTools. ### Setup Sumatra @@ -136,9 +152,13 @@ Finally, you need to ensure that the `distro` setting is correct. The possible v ### Distribution -You need to install TeXLive. +On **Linux**, both [TeXLive](https://www.tug.org/texlive/) and [MiKTeX](http://miktex.org/) (since version 2.9.6300) are supported. + +- TeXLive + We highly recommend installing the version directly from TUG, which can be found [here](https://www.tug.org/texlive/acquire-netinstall.html) rather than the version included with your distribution, as TeXLive is generally updated more regularly and tends to include more features. In particular, if you are on Ubuntu, note that `apt-get install texlive` will get you a working but incomplete setup. For example, it will *not* install `latexmk`, which is essential to LaTeXTools. You need to install it via `apt-get install latexmk`. However, as long as the expected binaries are available on your system, LaTeXTools should generally work. -We highly recommend installing the version directly from TUG, which can be found [here](https://www.tug.org/texlive/acquire-netinstall.html) rather than the version included with your distribution, as TeXLive is generally updated more regularly and tends to include more features. In particular, if you are on Ubuntu, note that `apt-get install texlive` will get you a working but incomplete setup. For example, it will *not* install `latexmk`, which is essential to LaTeXTools. You need to install it via `apt-get install latexmk`. However, as long as the expected binaries are available on your system, LaTeXTools should generally work. +- MiKTeX + We recommend following the [Official Guide](https://miktex.org/download#unx) to install, initialize, update, etc., and turn on automatic installation. One such package that is missing is `latexmk`, which is a script for building LaTeX documents, which LaTeXTools uses by default. You can either choose to install `latexmk` or [change the builder](#builder.md) to use a builder that does not require `latexmk`. To install `latexmk`, you can either use the **MiKTeX Console** or from the **Terminal** type `sudo mpm --admin --install latexmk` or `mpm --install latexmk`, which will prompt you for your password and install the `latexmk` package. You can use the **LaTeXTools: Check System** command to ensure that the expected binaries are found. diff --git a/docs/settings.md b/docs/settings.md index c74c6d3f4..dae3486b1 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -69,11 +69,12 @@ This section refers to setting that can be found in a platform-specific block fo ### All Platforms + * `distro` (`texlive`): either `miktex` or `texlive` (include MacTeX), depending on your TeX distribution. * `texpath` (varies): the path to TeX & friends. Note that this should always include `$PATH` to ensure the default path is loaded as well. ### Windows - * `distro` (`miktex`): either `miktex` or `texlive`, depending on your TeX distribution + * `distro` (`miktex`): either `miktex` or `texlive`, depending on your TeX distribution. * `sumatra` (`""`): leave blank or omit if the SumatraPDF executable is in your `PATH` and is called `SumatraPDF.exe`, as in a default installation; otherwise, specify the *full path and file name* of the SumatraPDF executable. * `sublime_executable` (`""`): this is used if `keep_focus` is set to true and the path to your sublime_text executable cannot be discovered automatically. It should point to the full path to your executable `sublime_text.exe`. * `keep_focus_delay` (`0.5`): this is used if `keep_focus` is set to true. It controls how long (in seconds) the delay is between the completion of the `latextools_jump_to_pdf` command and the attempt to refocus on Sublime Text. This may need to be adjusted depending on your machine or configuration. @@ -100,7 +101,7 @@ This section refers to setting that can be found in a platform-specific block fo **Note:** Since the build system is meant to be fully customizable, if you use a third-party builder (which hopefully will become available!), you need to refer to its documentation. * `builder` (`"traditional"`): the builder you want to use. Possible values: - * `"default"` or `""` or `"traditional"`: this is the standard LaTeXTools builder, which builds the document using `texify` on MiKTeX or `latexmk` on TeXLive or MacTeX. The majority of the documentation is written assuming you are using this builder. + * `"default"` or `""` or `"traditional"`: this is the standard LaTeXTools builder, which builds the document using `texify` on MiKTeX that is missing `Perl` interpreter and `latexmk` MiKTeX package, using `latexmk` on MiKTeX or TeXLive (include MacTeX). The majority of the documentation is written assuming you are using this builder. * `"basic"`: invokes `pdflatex` / `xelatex` / `lualatex` to build the document. If the log indicates it is necessary, it then runs `biber` or `bibtex` and then two additional runs of `pdflatex` / `xelatex` / `lualatex`. Mostly supports the same features as the `traditional` builder. * `"script"`: invokes the set of commands specified in the `"script_commands"` setting in the platform-specific part of the `"builder_settings"`. See [the documentation](available-builders.md#script-builder) for details. * `"simple"`: invokes `pdflatex` 1x or 2x as needed, then `bibtex` and `pdflatex` again if needed; intended mainly as a simple example for people writing their own build engines. @@ -112,8 +113,8 @@ This section refers to setting that can be found in a platform-specific block fo For the `default`/`traditional` builder, the following settings are useful: * `program` (unset): one of `pdflatex` (the default), `xelatex` or `lualatex`. This selects the TeX engine. * `command` (unset): the precise `latexmk` or `texify` command to be invoked. This must be a list of strings. The defaults (hardcoded, not shown in the settings file) are: - * (TeXLive): `["latexmk", "-cd", "-e", "-f", "-%E", "-interaction=nonstopmode", "-synctex=1"]` - * (MiKTeX): `["texify", "-b", "-p", "--engine=%E", "--tex-option=\"--synctex=1\""]` + * (MiKTeX and TeXLive): `["latexmk", "-cd", "-e", "-f", "-%E", "-interaction=nonstopmode", "-synctex=1"]` + * (MiKTeX is missing `Perl` interpreter and `latexmk` MiKTeX package): `["texify", "-b", "-p", "--engine=%E", "--tex-option=\"--synctex=1\""]` * `options` (unset): allows you to specify a TeX option, such as `--shell-escape`. This must be a tuple: that is, use `options: ["--shell-escape"]` The `basic` builder also supports the `program` and `options` options. For the script builder, the following setting is **required**: diff --git a/latextools_utils/output_directory.py b/latextools_utils/output_directory.py index cc5b67d5d..346cc8bff 100644 --- a/latextools_utils/output_directory.py +++ b/latextools_utils/output_directory.py @@ -6,6 +6,7 @@ from . import get_setting from .distro_utils import using_miktex +from .perl_latexmk_installed import perl_latexmk_installed from .tex_directives import get_tex_root, parse_tex_directives from .sublime_utils import get_project_file_name @@ -32,7 +33,7 @@ class UnsavedFileException(Exception): # return_setting indicates that the raw setting should be returned # as well as the auxiliary directory def get_aux_directory(view_or_root, return_setting=False): - # not supported using texify or the simple builder + # not supported the Tex Live distro or using texify or the simple builder if not using_miktex() or using_texify_or_simple(): if return_setting: return (None, None) @@ -195,7 +196,7 @@ def get_jobname(view_or_root): def using_texify_or_simple(): if using_miktex(): builder = get_setting('builder', 'traditional') - if builder in ['', 'default', 'traditional', 'simple']: + if (builder == 'simple' or not perl_latexmk_installed()): return True return False diff --git a/latextools_utils/perl_latexmk_installed.py b/latextools_utils/perl_latexmk_installed.py new file mode 100644 index 000000000..7a0e57934 --- /dev/null +++ b/latextools_utils/perl_latexmk_installed.py @@ -0,0 +1,9 @@ +import os +from shutil import which +from .external_command import get_texpath + + +def perl_latexmk_installed(): + """Return whether perl and latexmk is available in the PATH.""" + texpath = get_texpath() or os.environ['PATH'] + return which('perl', path=texpath) and which('latexmk', path=texpath) diff --git a/system_check.py b/system_check.py index f9a9b8d3b..8feb869c2 100644 --- a/system_check.py +++ b/system_check.py @@ -400,10 +400,17 @@ def run(self): # a list of programs, each program is either a string or a list # of alternatives (e.g. 32/64 bit version) - programs = [ - 'latexmk' if not self.uses_miktex else 'texify', 'pdflatex', - 'xelatex', 'lualatex', 'biber', 'bibtex', 'bibtex8', 'kpsewhich' - ] + # Add check "perl" and "latexmk" when Miktex + if self.uses_miktex: + programs = [ + 'latexmk', 'perl', 'texify', 'pdflatex', + 'xelatex', 'lualatex', 'biber', 'bibtex', 'bibtex8', 'kpsewhich' + ] + else: + programs = [ + 'latexmk', 'pdflatex', + 'xelatex', 'lualatex', 'biber', 'bibtex', 'bibtex8', 'kpsewhich' + ] # ImageMagick requires gs to work with PDFs programs += [['magick', 'convert']]