-
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
cmd get_current returns empty if optional arguments are after mandatory ones #1983
Comments
It would help if you can be more clear what you think is wrong and how you think it should be fixed. As it stands, I have to guess. Even though I probably guess right, it is much better if I don't need to guess. My guess: You think I should update Note: As explained, it is really hard or impossible to actually determine if something is an actual argument/option group or not, so we need to specify a behaviour that works as expected nearly always, but that we must allow to probably fail in some cases. We won't achieve perfect, so let's figure out the next best thing. I think I'm pretty close, but I'll accept that the current behaviour might need an update, but this would require a slightly clearer description and explanation. |
Yes, I think you got it right :) Will keep a note on adding more exact note on expected behavior in future. Yes this syntax P.S. I have seen macros with optional arguments on both ends of mandatory arguments like |
The question is: should we allow spaces between $\frac{1}{2} {\color{red} a}$ % how to prevent the last {...} to be recognized as an argument? Whatever we do, it will end up being wrong in some way. Still, if The current behaviour allows any number of whitespace characters, including newlines. My current idea is that it seems relatively safe to adjust the behaviour as follows:
I think a possible alternative is to adjust step 4 to greedily match first |
@lervag Good point, I think it boils down to this rule: Starting from the macro name What does "touch" mean?
I did some testing on a sample tex file I have that has
and it seems like spaces are allowed between some of the arguments of This pattern compiles:
and this too:
But this does not compile (as atleast one line does not end with
Feel free to ask more questions, and you can also refer this on https://tex.stackexchange.com to see what TeX experts have to say about my proposal. |
And, regarding Lastly, it will be a great addition of capability if the the API can give one more information: The number of argument cursor is in. For instance in a macro command like this: Update (from prior observation): Also, this example |
First, a minor comment: it is a relatively large mental effort to parse big "walls of text", and since I can't focus on a single issue for a lot of time in one go, this can become a barrier for me wrt. focus on actually implementing anything. So, to get progress here, it would be very beneficial to get a short and concise summary of what we want done here. If it is a short proposal that makes sense, then we can also allow others to comment on it before I act. So, I propose the following: we finish this discussion with the goal of having a short and simple definition of where we want to go, then we open a new issue where this is clearly stated where we/I can invite for some more comments before I implement the changes. I want to do this carefully, because I don't want to break things for anyone, and we are now discussing a relatively deep point in the VimTeX APIs. So, my current idea of this thread is the following: Feature request
We should also adhere to the following special cases and considerations:
The latter requirement is actually a little bit complicated. The current behaviour does not allow newlines. |
@lervag Sure, its good idea to have a proposal ticket with just a clear proposal! Regarding your special considerations:
Yes I understand, it could be staggered, and perhaps lower priority. Most of the well formatted code I come across on https://tex.stackexchange.com/, (which also happens to be intuitive) looks like code below, where opening delimiter of new argument and closing delimiter of previous argument are on same line and have no whitespace in between (like
|
Very sorry about lack of progress here; it's simply been to much the last half year so this did not get high enough priority. But I finally got around to it and I've opened a PR. Let's continue the discussion there: #2197 |
vimtex#cmd#get_current()
explained in comment: #1981 (comment), returns an empty value if optional argument is after curly argument, unless the name of the macro is\begin
.Why distinguish between color of optional arguments of
\begin
, and those of\setmainfont
. Both are just macros for TeX/LaTeX. Perhaps this is rooted in the fact that earlier commands in TeX world required optional argument to be before mandatory ones. That restriction does not exist for modernkey-value
based commands, of which there are many... includingfontspec
macros. Most of thefontspec
code online uses this syntax pattern: optional font parameters after font name. This will also truly resolve #1981I came across this problem while after coding a function to determine the name of the current command/enviornment. Put the following in your vimrc file, move the cursor to parts of macro arguments (in a
.tex
file), hit<C-r>
, and read messages with:messages
Sample code block from above screenshot: (as you will notice, pressing
<C-r>
inside[]
of\setmainfont
will returnERROR: cmd empty
)The text was updated successfully, but these errors were encountered: