SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 365 forks source link

use own packages in math live preview #1382

Closed Lauge1006 closed 5 years ago

Lauge1006 commented 5 years ago

Got a problem with the math live preview function (which btw. is fantastic) :) I have a file "mypreamble.sty" in the same folder as the .tex file, which is then imported to the .tex file. How do you include these manually defined \newcommands in the math live preview, so that you own commands can be interpreted in the preview?

Writing "\usepackage{mypreamble}", in the file LaTeXTools.sublime-settings (obviosly) does not work, it does not find my own package. how should i do that? I assume i have to copy mypreamble.sty to the folder where the math live preview searches for the other packages. (importing build-in packages into math live preview works fine btw).

Best, Lauge

r-stein commented 5 years ago

The main problem with including files in the live preview is that for performance reasons the generated images are cached based of the content of the document, which is used to generate the preview. I.e. if you \usepackage{mypreamble} and then change something in mypreamble.sty it would not invalidate the cached images. Therefore including local files for the file preview is not supported.

You may try to copy the file to folder where the preview thumbnails are generated. You can get the folder by opening the ST console ctrl+` and then pasting this:

import os; from LaTeXTools.latextools_utils import cache; os.path.join(cache._global_cache_path(), 'preview_math')

Keep in mind that this folder is deleted when you clear the cache, so the file may just disapear after a while.

Lauge1006 commented 5 years ago

it works! :) thanks alot! i will just clear the cache manually then, or put the file into the folder when it disappears. the code btw gave this directory: 'C:\Users\name\AppData\Local\Sublime Text 3\Cache\LaTeXTools\internal\preview_math'

r-stein commented 5 years ago

Note: The directory differs on several factors "Sublime Text 2 vs Sublime Text 3", "Linux vs OSX vs Windows", "Portable vs normal installation". So you are using a installed Sublime Text 3 on a Windows machine :) On windows you can also use the startfile command to open the folder:

import os; from LaTeXTools.latextools_utils import cache; os.startfile(os.path.join(cache._global_cache_path(), 'preview_math'))