SublimeText / LaTeXTools

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

Show images on hover when they're wrapped in a custom command #1483

Closed quantumgolem closed 4 years ago

quantumgolem commented 4 years ago

I usually wrap the \includegraphics command inside a different command, such as \img, so that I can do things like centering them easily. Would it in any way be possible to show images when hovering over these custom commands that include the \includegraphics command? Here is an example of how I define the \img command:

\newcommand{\img}[4]{
  \begin{figure}[h]
    \includegraphics[#1]{#2}
    \centering
    \caption{#3}
    \label{#4}
  \end{figure}
}

...

\img{width=5cm}{my_image}{My image}{fig:my_imae}
ig0774 commented 4 years ago

So to generate image previews, we rely on the LaTeX syntax file for ST, in particular, on the scopes you can see here. While it not impossible to support a custom syntax, you'd have to create your own copy of the LaTeX syntax that sets the appropriate scopes correctly.

The other possibility would be to define a LaTeX noop command and then include the corresponding \includegraphics command, e.g.,

\newcommand{\nop}[1]{}

...

\img{width=5cm}{my_image}{My image}{fig:my_imae}
\nop{\includegraphics{my_image}}
quantumgolem commented 4 years ago

Thanks for the reply! That no operation command seems to be the easiest way to get this done.