Skip to content
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

Custom conceal rules #2634

Closed
Fireond opened this issue Feb 19, 2023 · 8 comments
Closed

Custom conceal rules #2634

Fireond opened this issue Feb 19, 2023 · 8 comments

Comments

@Fireond
Copy link

Fireond commented Feb 19, 2023

I have learned the command g:vimtex_syntax_custom_cmds but it seems it cannot support options for args and custom argstyle. For example, I want to conceal \ket{\psi} to |ψ>, conceal \bra{A\varphi} to <Aφ| (conceal \ket{}, \bra{}... commands to braket like. Thanks!

@Fireond
Copy link
Author

Fireond commented Feb 19, 2023

Also I wonder if it is possible to change concealchar key to concealstring key, say if I want to conceal \rank A to simply rank A, but the char limit the concealment to only one word.

@lervag
Copy link
Owner

lervag commented Feb 19, 2023

I have learned the command g:vimtex_syntax_custom_cmds but it seems it cannot support options for args and custom argstyle. For example, I want to conceal \ket{\psi} to |ψ>, conceal \bra{A\varphi} to <Aφ| (conceal \ket{}, \bra{}... commands to braket like. Thanks!

What you are asking for is unfortunately a much more complicated conceal. It is possible by use of some hacks. I'll see if I can make a function that generalizes this for commands like \cmd{arg} so that we can have it replaced with XargY where X and Y are single characters that are provided as arguments.

Also I wonder if it is possible to change concealchar key to concealstring key, say if I want to conceal \rank A to simply rank A, but the char limit the concealment to only one word.

No; VimTeX uses the legacy syntax engine and it does not have the concept of a concealstring. See :help syn-cchar for information on what is used for conceals by VimTeX.

@lervag
Copy link
Owner

lervag commented Feb 19, 2023

I've pushed an update that may resolve this. Please see :help vimtex_syntax_custom_cmds_with_concealed_delims and let me know what you think.

@Fireond
Copy link
Author

Fireond commented Feb 20, 2023

Thanks! But it seems this command not work well on my neovim: I type \ket{x} but it just conceal to {x}, and I just use the example config. I havn't found the cause.

lervag added a commit that referenced this issue Feb 20, 2023
@lervag
Copy link
Owner

lervag commented Feb 20, 2023

Sorry, my mistake. I've pushed a new update that I think works better.

@Fireond
Copy link
Author

Fireond commented Feb 22, 2023

It works! But when the containing args have {}, like \ket{\psi_{i}}, it would fail. I don't know whether there are techniques that can detect braces to avoid this error.
image
image

@lervag
Copy link
Owner

lervag commented Feb 22, 2023

Ah, yes. That is a much harder problem, because for the conceals to work, we need to match the region start and region end with the concealed groups. This means that we need the keepend argument for the syntax region command, and then we get the problem you mention now.

The example you give is trivial, though, because you could write it as \ket{\psi_i}; but your point is still valid because you might want \ket{\psi_{i+1}}.

lervag added a commit that referenced this issue Feb 22, 2023
@lervag
Copy link
Owner

lervag commented Feb 22, 2023

I think I found another way to do it. Please update and test again.

@lervag lervag closed this as completed Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants