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

Add conceal for \lvert, \rvert... #2186

Closed
Freed-Wu opened this issue Sep 30, 2021 · 22 comments
Closed

Add conceal for \lvert, \rvert... #2186

Freed-Wu opened this issue Sep 30, 2021 · 22 comments

Comments

@Freed-Wu
Copy link
Contributor

Describe the solution you'd like

e.g.

syntax match texMathSymbol "\\lvert"               contained conceal cchar=|
syntax match texMathSymbol "\\lVert"               contained conceal cchar=ǁ
syntax match texMathSymbol "\\rvert"               contained conceal cchar=|
syntax match texMathSymbol "\\rVert"               contained conceal cchar=ǁ

test

$$\lVert \mathrm{w} \rVert_2^2$$

image

lervag added a commit that referenced this issue Sep 30, 2021
@lervag
Copy link
Owner

lervag commented Sep 30, 2021

Done.

@lervag lervag closed this as completed Sep 30, 2021
@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 5, 2022

A package named physics provide the macro \abs{w} and \norm{w} to wrap \lverb w\rverb and \lVerb w\rVerb. Can them be concealed like \verb? Thanks!

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 5, 2022

And I think

syntax match texCmdAccent   "\\i\>"  conceal cchar=ı
syntax match texCmdAccent   "\\j\>"  conceal cchar=ȷ

is correct, just like \O and \o.

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 5, 2022

How about

syntax match texCmdAccent   "\\lq\>"  conceal cchar=`
syntax match texCmdAccent   "\\rq\>"  conceal cchar='

? Maybe punctuations can be concealed.

lervag added a commit that referenced this issue Feb 6, 2022
@lervag
Copy link
Owner

lervag commented Feb 6, 2022

A package named physics provide the macro \abs{w} and \norm{w} to wrap \lverb w\rverb and \lVerb w\rVerb. Can them be concealed like \verb? Thanks!

I assume you mean \vert here? This is somewhat harder to do. I know a method, but is really quite hacky. I think it may be better to not go there...

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 7, 2022

Oh, I see. Vim' conceal seems to be able to support only one character. Thanks!

@lervag
Copy link
Owner

lervag commented Feb 7, 2022

Yes, precicely. I could conceal the initial \abs{ and the suffix } individually, but the matching is then more complex and error prone. So I'm not sure if it is worth the effort.

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 8, 2022

I found \backslash has been concealed to \ in math mode. How about concealing \slash to /? It can work in non-math mode and math mode.

lervag added a commit that referenced this issue Feb 8, 2022
@lervag
Copy link
Owner

lervag commented Feb 8, 2022

Yes, no problem. I've added it as a "fancy" conceal.

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 9, 2022

In tex,

`'

``''

!`

?`

will output

‘’

“”

¡

¿

I notice double quotes has been concealed in vimtex:

" autoload/vimtex/syntax/core.vim:1832-1833
syntax match texLigature    "``"     conceal cchar=“
syntax match texLigature    "''"     conceal cchar=”

How about others?

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 9, 2022

And in tex, \sb, \sp have same function as _ and ^, 1\over2 have same function as \frac12. Should them be concealed, too?

@lervag
Copy link
Owner

lervag commented Feb 9, 2022

I'm not sure. I don't think we should aim for "full rendering". I might agree that 1 \over 2 is ok as an alternative to \frac 1 2, although all of this do feel a little bit like adding bloat. Do you find that you truly miss these conceals?

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 9, 2022

I agree with you. If some of them are not easy to be realized and no one like these macros, support them are not valuable. However, if something don't be supported, the document should explain which macros aren't supported and why them are not supported to avoid some one has any confusion about them. Thanks!

@lervag
Copy link
Owner

lervag commented Feb 9, 2022

However, if something don't be supported, the document should explain which macros aren't supported and why them are not supported to avoid some one has any confusion about them. Thanks!

Sorry, but I don't agree. There are way too many elements that could be concealed to document every element that we don't conceal. My approach so far has been to be pragmatic - if someone suggests something that should be concealed and where I agree it has value, I try to add it. In some cases I say no, either because of complexity or because I don't see the value. If I were to document every decision it would i) make the documentation more bloated, and ii) add to the already high workload of maintaining VimTeX.

I would not mind considering PR's, though. Perhaps I'm wrong about i) and it could be possible to add these things to the docs in a good way. But I will personally prioritize other activities that I believe brings more value to the community.

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 9, 2022

There are way too many elements that could be concealed to document every element that we don't conceal. My approach so far has been to be pragmatic - if someone suggests something that should be concealed and where I agree it has value, I try to add it. In some cases I say no, either because of complexity or because I don't see the value.

Thanks for your explanation. Add some not complex and valuable function is the true duty. So just add some necessary conceal is enough.

So, can it be supported? Thanks!

diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim
index 333e140a..22801934 100644
--- a/autoload/vimtex/syntax/core.vim
+++ b/autoload/vimtex/syntax/core.vim
@@ -1828,9 +1828,13 @@ function! s:match_conceal_accents() abort " {{{1
   syntax match texCmdLigature "\\ss\>" conceal cchar=ß
   syntax match texLigature    "--"     conceal cchar=–
   syntax match texLigature    "---"    conceal cchar=—
+  syntax match texLigature    "`"     conceal cchar=‘
+  syntax match texLigature    "'"     conceal cchar=’
   syntax match texLigature    "``"     conceal cchar=“
   syntax match texLigature    "''"     conceal cchar=”
   syntax match texLigature    ",,"     conceal cchar=„
+  syntax match texLigature    "!`"     conceal cchar=¡
+  syntax match texLigature    "?`"     conceal cchar=¿
 endfunction

@lervag
Copy link
Owner

lervag commented Feb 9, 2022

I'm not so sure about concealing the ` and ', but I'll add the other two immediately. The former: would it not be confusing?

lervag added a commit that referenced this issue Feb 9, 2022
@Freed-Wu
Copy link
Contributor Author

Thanks.

Maybe can try ' and ```, then see if any bug will happen?

@lervag
Copy link
Owner

lervag commented Feb 10, 2022

Maybe can try ' and ```, then see if any bug will happen?

What do you mean? Reg.

  syntax match texLigature    "`"     conceal cchar=‘
  syntax match texLigature    "'"     conceal cchar=’

my point was that I believe these conceals may be confusing to the user. Perhaps I'm wrong. If you disagree and still think these will be useful, then OK, I'll add them.

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 10, 2022

I'm not offensive...:(

I want to know which situation these conceals will be confusing? Did you mean any code like \catcode`\@ = \active or other situations I don't know about ```? These situations maybe happen. In my opinion, these conceals, can be provided as a key of g:vimtex_syntax_conceal, like:

let g:vimtex_syntax_conceal = {'ligature': 0}

By default, it is disabled. If anyone know what these ligature means, they can enable it by themselves. It should not effect too many people, I think.

@Freed-Wu
Copy link
Contributor Author

I also don't think these conceal will be used by many people especially who don't use any languages containing ligatures. However, Knuth designed them in Tex, so they looks like a standard (albeit not many people know and use). If provide an option to respect standard may be better. That is my opinion. No offend.

@lervag
Copy link
Owner

lervag commented Feb 10, 2022

I'm not offensive...:(

No offense taken, and I hope I don't come off as offensive myself - that is not my intention!

By default, it is disabled. If anyone know what these ligature means, they can enable it by themselves. It should not effect too many people, I think.

No, currently, this is enabled by default and is provided under the accents key. Perhaps we should separate and add ligatures as a new key? But it should be enabled by default, I think, else it will be a breaking change.

I also don't think these conceal will be used by many people especially who don't use any languages containing ligatures. However, Knuth designed them in Tex, so they looks like a standard (albeit not many people know and use). If provide an option to respect standard may be better. That is my opinion. No offend.

Again, no offense. I just want to think things through before I implement them. But OK, I'll add the suggested conceals as well together with the new ligatures key that allows more fine grained control if anyone should not like this. It's a good compromise, I think.

lervag added a commit that referenced this issue Feb 10, 2022
@Freed-Wu
Copy link
Contributor Author

Thanks for your explanation. I support this change.

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