-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for SageTeX #2027
Comments
WorkaroundAdd this to let s:TeX_indentexpr=&indentexpr " backup the normal values
let s:TeX_indentkeys=&indentkeys
augroup TeXInlineBlocks
auto!
if !exists("s:Lua_indentkeys")
unlet b:did_indent
source $VIMRUNTIME/indent/lua.vim
let s:Lua_indentkeys=&indentkeys
let &indentexpr=s:TeX_indentexpr
endif
call SyntaxRange#Include('^\s*\\begin{luacode\*}', '\\end{luacode\*}', 'lua', 'Statement')
call SyntaxRange#Include('^\s*\\directlua\s*{', '}', 'lua', 'Statement')
call OnSyntaxChange#Install("LuaEnvironmentInTeX", "^synIncludeLua$", 1, "a")
auto User SyntaxLuaEnvironmentInTeXEnterA set indentexpr=GetLuaIndent() | let &indentkeys=s:Lua_indentkeys
auto User SyntaxLuaEnvironmentInTeXLeaveA let &indentexpr=s:TeX_indentexpr | let &indentkeys=s:TeX_indentkeys
if !exists("s:Python_indentkeys")
unlet b:did_indent
source $VIMRUNTIME/indent/python.vim " to define that function ^^ (assuming the internal indentation function is named GetPythonIndent)
let s:Python_indentkeys=&indentkeys
let &indentexpr=s:TeX_indentexpr " revert the indent
endif
call SyntaxRange#Include('\\begin{python}', '\\end{python}', 'python', 'Statement')
call SyntaxRange#Include('\v\\(py|pyc|pyq|pycq)\s*\{', '}', 'python', 'Statement')
call OnSyntaxChange#Install("PyEnvironmentInTeX", "^synIncludePython$", 1, "a")
auto User SyntaxPyEnvironmentInTeXEnterA set indentexpr=GetPythonIndent(v:lnum) | let &indentkeys=s:Python_indentkeys
auto User SyntaxPyEnvironmentInTeXLeaveA let &indentexpr=s:TeX_indentexpr | let &indentkeys=s:TeX_indentkeys
augroup END For this one indentation while editing is correct; however To partially make behavior of Line 102 in 60bec44
to add the environment name. (or use some Implementing the normal way (without changing indentexpr) is possible, but depends on the internal implementation details of Python indentation plugin -- see for example how html.vim implement indentation of inline JavaScript, or how vim.vim implement |
Thinking about it, the user may use several packages which define new verbatim-like environment ( |
Thanks! Sorry for taking so long before addressing this, but life's been very busy lately!
This really is quite a hard problem, and I'm not sure I'm interested in addressing it myself. I may consider pull requests.
Same as above.
Same as above.
Same. The thing that makes all of the above hard is that Vim is not really designed to support multiple file types in a single file. For Neovim, there is Tree-sitter, which I believe in the future will actually allow relatively simple solutions to perhaps all of the above. But it is still not so mature, and Tree-sitter syntax highlighting is currently not as good as the syntax highlighting provided by VimTeX. That may change, perhaps even relatively soon. However, I do not currently plan to build VimTeX around Tree-sitter. So features in this direction will probably be built by other enthusiasts. Sorry.
I think such workarounds are interesting, and it may be relevant to document them in the VimTeX docs.
I'm not really "acquainted" with sagetex, so whether you should provide the more advanced example is more or less up to you. But if we agree on desired changes to VimTeX, then I might ask for specific examples. In any case, thanks for providing the example. Thanks for providing another idea for a workaround.
Well, yes and no. I believe it is better to add specific support to various packages, as that allows us to handle things in a better manner. Let's focus on SageTeX now. If you think the above still holds after you see what I mean, then feel free to open a new issue and repeat the suggestions. |
So, the question is then: what do we mean with support for SageTeX? My proposal is to add support for the various SageTeX environments and comments within which we should assume nested Python syntax. This would mean that e.g. within a |
I've now added initial syntax support to |
Feature request ("what")
I'd like to suggest that support for the
SageTeX
package be "officially" added to vimtex.This has been suggested before, but as the issue was closed because of apparent lack of interest, I'm opening a new one.
Disclaimer
Although I've been using vim a lot recently, I'm not an expert by any means, so it's possible that there's an obvious solution to the problems I list below which doesn't involve any extra features. In which case, I apologize.
Background ("why")
The Good
First of all, I'm a huge fan of vimtex---I use it nearly every day for note-taking, homework, and scratch work (I'm a grad student in physics).
I'm also a huge fan of using Sage for computations, and it is incredibly convenient to be able to embed simple calculations directly into the markup of a mathematical document via SageTeX. Recently I've become comfortable enough with Sage that almost all my LaTeX documents include some embedded Sage code---for instance, I routinely use Sage (which is really just Python with extra stuff) to construct tedious bits of markup like tables. (See below for an example of this kind of document structure.)
The Bad
Unfortunately, editing Sage code, e.g. embedded in a
\begin{sagesilent} ... \end{sagesilent}
environment, is not very functional at the moment. This is becauseThe Ugly
My current workaround is via the syntax-range plugin, and looks like this:
This works...somewhat OK, in that the local indentation rules seem to respect the Sage filetype. In other words, when I open a new line in a Sage codeblock, it's opened at a sensibly-indented position with respect to the previous line.
However, periodically---on writes, and when adding certain kinds of textobjects (single- and double-quotes, e.g.)---the line I'm editing will be auto-maliciously re-indented to match the line above it, which of course renders the resulting code invalid as Python. And of course, typing
gg=G
, which I'm in the habit of doing semi-regularly, just destroys the fragile Python indentation in any fenced blocks...so I periodically have to manually re-indent significant chunks of code, which gets annoying after awhile.Examples
Below is a fairly minimal example showing my most common use-cases: the
sagesilent
environment and\sagestr{}
command. It won't compile with SageTeX but should compile with LaTeX; if necessary I can modify it further so that it compiles with both.The text was updated successfully, but these errors were encountered: