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

Concealment of \citet and \citep from natbib #2658

Closed
1 of 5 tasks
kiryph opened this issue Mar 4, 2023 · 4 comments
Closed
1 of 5 tasks

Concealment of \citet and \citep from natbib #2658

kiryph opened this issue Mar 4, 2023 · 4 comments

Comments

@kiryph
Copy link
Contributor

kiryph commented Mar 4, 2023

I am wondering whether the concealment of \citet and \citep from natbib can be improved.

Here a screenshot from the documentation of natbib

Screenshot 2023-03-04 at 07 53 46

The corresponding code is

\documentclass{article}
\usepackage{natbib}

\begin{document}
\citet{jon90}
\citet[chap.~2]{jon90}
\citep{jon90}
\citep[chap.~2]{jon90}
\citep[see][]{jon90}
\citep[see][chap.~2]{jon90}
\citet*{jon90}
\citep*{jon90}
\end{document}

Currently concealed as following

Screenshot 2023-03-04 at 08 11 21

The most obvious change could be:

  • show \citep*?{jon90} with parentheses instead of square brackets (third and last line).

Prepend optional parameters and replace inner brackets with spaces

  • Conceal \citet[chap.~2]{jon90} as [chap. 2 jon90]
  • Conceal \citep[see][]{jon90} as (see jon90)
  • \citep[see][chap.~2]{jon90}. Here the chapter reference becomes completely invisible. I would at least show it. Showing it with less square brackets, e.g. as (see chap. 2 jon90).
  • for \citet one could drop the surrounding square brackets. Here I am not so sure.

I am not totally sold on all my suggestions and what is possible to mimic natbib functionality

lervag added a commit that referenced this issue Mar 5, 2023
@lervag
Copy link
Owner

lervag commented Mar 5, 2023

The first one seems simple and I've fixed it already. The other ones will require some more thought.

  • Conceal \citet[chap.~2]{jon90} as [chap. 2 jon90]
  • Conceal \citep[see][]{jon90} as (see jon90)

These are quite hard. We are parsing from left to right, and we are parsing group by group. Currently, I'm relying on nextgroup= and I'm allowing two optional groups:

syntax match texCmdRefConcealed "\\citet\?\>\*\?" conceal
\ skipwhite nextgroup=texRefConcealedOpt1,texRefConcealedArg
call vimtex#syntax#core#new_opt('texRefConcealedOpt1', {
\ 'opts': g:vimtex_syntax_conceal_cites.verbose ? '' : 'conceal',
\ 'contains': '@texClusterOpt,texSpecialChar',
\ 'next': 'texRefConcealedOpt2,texRefConcealedArg',
\})
call vimtex#syntax#core#new_opt('texRefConcealedOpt2', {
\ 'opts': 'conceal',
\ 'contains': '@texClusterOpt,texSpecialChar',
\ 'next': 'texRefConcealedArg',
\})

That is a simple but effective implementation.

To enable what you are asking, we would instead need to somehow match the entire optional groups in one go. It may be possible, but I don't quite see how to do it. Perhaps we can use the pattern offsets here (:help syn-pattern-offset) with end="{"me-1 or something similar. Then we could conceal any ]\_s*[ by a single space character. I would need to experiment a bit with this.

  • \citep[see][chap.~2]{jon90}. Here the chapter reference becomes completely invisible. I would at least show it. Showing it with less square brackets, e.g. as (see chap. 2 jon90).

Yes, I agree. I'll find a way to only hide the second option if it is empty.

  • for \citet one could drop the surrounding square brackets. Here I am not so sure.

I think having the square brackets makes it easier to recognize that this is a concealed \citet command, and as such, is useful.

@kiryph
Copy link
Contributor Author

kiryph commented Mar 7, 2023

It may be possible, but I don't quite see how to do it.

Do not invest too much time in this issue. If there is no obvious way, keep the current way. It works.

Yes, I agree. I'll find a way to only hide the second option if it is empty.

That would be great and would resolve, from my point of view, the most urgent part of this issue.

I think having the square brackets makes it easier to recognize that this is a concealed \citet command, and as such, is useful.

Agreed. Leave it as it is.

@lervag
Copy link
Owner

lervag commented Mar 9, 2023

Then I believe the last patch should suffice. Clearly, this is not perfect, but it is not too bad either.

@lervag lervag closed this as completed Mar 9, 2023
@kiryph
Copy link
Contributor Author

kiryph commented Mar 9, 2023

Thanks. Now the concealed lines look like
Screenshot 2023-03-09 at 14 15 23

And yes, now one can see in line 10 the chapter reference.

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