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

Conceal additional commands like \section{} and \texttt{} #1978

Closed
mawkler opened this issue Mar 4, 2021 · 4 comments
Closed

Conceal additional commands like \section{} and \texttt{} #1978

mawkler opened this issue Mar 4, 2021 · 4 comments

Comments

@mawkler
Copy link

mawkler commented Mar 4, 2021

VimTeX conceals some commands like for instance \textbf{}, \textit{} which I love.

Is there any plan to conceal more commands? The ones that I personally miss the most are for \section{}/\subsection{}/\subsubsection{} and \texttt.

For \texttt{} I think that the surrounding command should be concealed and the text inside it should get a syntax highlighting.

As for \...section, in order to differentiate between the different levels it could for instance get concealed into the markdown syntax like this:

Without conceal:

\section{First Section}
Foo bar

\subsection{Second Section}
Foo bar

\subsubsection{Third Section}
Foo bar

With conceal:

# First Section
Foo bar

## Second Section
Foo bar

### Third Section
Foo bar

Would this be possible to implement?

@lervag
Copy link
Owner

lervag commented Mar 8, 2021

VimTeX conceals some commands like for instance \textbf{}, \textit{} which I love.

:)

(I personally don't like it, but I understand it is a popular feature!)

Is there any plan to conceal more commands? The ones that I personally miss the most are for \section{}/\subsection{}/\subsubsection{} and \texttt.

No plan except that I'll be glad to improve as suggestions are provided, such as this.

For \texttt{} I think that the surrounding command should be concealed and the text inside it should get a syntax highlighting.

Ok, so: \texttt{asdf} -> asdf where asdf is given a specific highlighting; which kind, if so? This command is already matched as texCmdStyle, so I would propose that the contents would be texStyleArgTT.

As for \...section, in order to differentiate between the different levels it could for instance get concealed into the markdown syntax like this:
...
Would this be possible to implement?

Actually, no: syntax conceals only allow a single substitution character of the concealed text. In this particular case, we can conceal the \*section{...}, but we can't use more than a single character. So, we could do something like this:

% before
\section{sec}
\subsection{subsec}

% after
¤sec
#subsec

The initial character can be chosen quite freely, but we can't add a space separator or use multiple characters.

Thus, I'm not sure if concealing the \section family of commands is a very good idea?

@lervag
Copy link
Owner

lervag commented Mar 8, 2021

By the way, conceal of \textttt is also covered by #1968, so let's discuss that part there and let this discussion be about the \section stuff.

@mawkler
Copy link
Author

mawkler commented Mar 12, 2021

which kind, if so?

The highlight group is just a name right? In that case texStyleArgTT sounds good to me. I would propose that it by default was linked to :hi String. This is what vim-markdown's highlight for inline code is linked to by default.

syntax conceals only allow a single substitution character of the concealed text

After some tinkering I was able to throw together this proof of concept that turns \section{Foo} to # Foo by dividing the pattern into different parts. I based it on this reddit thread and this stackoverflow answer :

syntax region Statement start='\\section{' end='}' transparent contains=section1,section2,section3
syntax match section1 '\\\%(section.*\)\@=' contained conceal cchar=#
syntax match section2 '\%(\\\)\@<=section{\ze\w\+' contained conceal cchar= " space
syntax match section3 '\%(section{\w\+\)\@<=}' contained conceal

set conceallevel=2

I'm not sure what the neatest way of getting it to also handle \subsection and \subsubsection is but hopefully this can help us achieve what we want.

@lervag
Copy link
Owner

lervag commented Apr 6, 2021

This is now implemented in #2022; please test and give some feedback. I've also added a couple of questions that I'd like to hear opinions on.

@lervag lervag closed this as completed Apr 6, 2021
lervag added a commit that referenced this issue Apr 7, 2021
lervag added a commit that referenced this issue Oct 9, 2021
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