Aerijo / autocomplete-latex

A LaTeX autocomplete provider for Atom
MIT License
10 stars 2 forks source link

Need more default completions #8

Open Aerijo opened 6 years ago

Aerijo commented 6 years ago

If anybody can think of a completion that would be useful for a lot of people, please share it here. You don't need to make a PR yourself, just explain:

  1. What the display text is (what appears in the popup box)
  2. What it should expand to
  3. Why it deserves to be included
  4. Which scopes it belongs in (e.g., everywhere, maths, table, ...)
werunom commented 6 years ago

I would suggest autocompletion for table command. This would be similar to the autocomplete for figure

  1. Display text - \table
  2. Should expland to the following
    \begin{table}
    \centering
    \begin{tabular}{}
    \end{tabular}
    \caption{}
    \label{}
    \end{table}
  3. Table command is quite basic and often used.
  4. scope - everywhere
werunom commented 6 years ago

Would suggest all the citation commands. Currently, only \autocite is included.

Similar commands - \cite, \parencite, \textcite, \citetitle (to mention the ones I use)

Aerijo commented 6 years ago

@werunom Added table completion & the suggested cite commands.

werunom commented 6 years ago

Would suggest adding formatting commands (\textbf{}, \textit{}, \emph{}, and many more). But here, there are two ways of implementing them.

  1. Straightforward way to do this is to what is already done for other autocompletions here - suggestions are shown when the command is written followed by a \

  2. Apart from the usual triggering by slash, hotkey insertion can also be provided since bold and italics are often used. E.g., selecting a text and pressing ctrl+b wraps the text with bold command (like \textbf{text}). This implementation is already present in latextools package. But sadly, this package is discontinued. So, stopped using it.

However, I am not sure whether the suggestion (2) falls under the purview of an autocomplete package. So, its upto you to decide whether this suggestion is within the design of the package. But given that there are already similar features in the present package (the @ completion is doing something similar), you can think of. So, use wise, implementation of (2) makes sense; but not sure whether that should be the job of a autocomplete package

werunom commented 6 years ago

Would suggest autocomplete of certain punctuations like double quotes (``text''), single quotes (`'), etc. Implementation wise, again there are two ways.

  1. Can be triggered by commands like \single, \double, etc.

  2. Apart from the above suggestion, can this be autocompleted similar to the default autocompletion of single and double quotes? That is, in latex scope, when " is pressed, instead of the following autocompletion "<cursor-here>", the following can be done ``<cursor-here>''. (Again, this was done by the latextools package.)

:)

werunom commented 6 years ago

I would suggest autocompletion for equation command.

  1. Display text - \equation
  2. Should expland to the following
    
    \begin{equation}

\end{equation}


3. quite basic and often used.
4. scope - maths
werunom commented 6 years ago

I would suggest autocompletion for quote command.

  1. Display text - \quote
  2. Should expland to the following
    
    \begin{quote}

\end{quote}


3. quite basic and often used.
4. scope - everywhere
Aerijo commented 6 years ago

@werunom sorry for the delay, I've been sidetracked on getting package name completion working. I'm also working on a script that takes different sets of completions that can be enabled/disabled at will. For example, the commands supplied by each package could be toggled individually. Same with groups for formatting (\textbf, etc.) and others.

Once I get that going, I'll add the suggested completions.

Regarding the bold, etc. shortcuts. I like it and will probably include it. However, it doesn't really fit the concept of 'autocompleting', so I might move it to a different package at some point in the future.

werunom commented 6 years ago

Autocompletion for inline equation syntax.

Till now, I was using $<equation-here>$ syntax for inline equations. But looks like the stricter form \(\) has slight advantages than easier one. See this.

But this stricter form is too cumbersome to type patiently given that $$ is so easy. Currently I have a snippet to overcome this. Thought this autocomplete can be added to this package as well.

Aerijo commented 6 years ago

@werunom I'll try it. I still prefer the readability of $...$ over \(...\), even if it can cause less informative errors. E.g., $a$ vs \(a\), $f(x)$ vs \(f(x)\). That's also why I haven't done anything to the PR on language-latex (well, that and I think snippets should be removed from that package anyway. Maybe when I convert all the snippets there to completions here...)

Having said that, \[\] is definitely the better choice (I even mark $$ as deprecated in language-latex2e. Sometimes I feel it gets a little obnoxious, but then I remember it's an objectively worse choice than \[\] and should never be used). I suppose if I support this kind of completion, it only makes sense to add \(\) as well.

I'll try it this way

{
  "displayText": "$",
  "snippet": "\\\\($1\\\\)$0",
},
{
  "displayText": "$$",
  "snippet": "\\\\[\n\t$1\n\\\\]$0",
},

Was this what you wanted? I also considered making the display text \\inline, as that would restrict the prefix to fewer valid characters which trigger completions. As it is, I had to add a minor change to the prefix logic, to ignore the minimum length if the first character of the prefix was $. Otherwise, any value of 2 or greater would make the $ inline snippet never show. I think that $ is more natural though, and what many will do by habit.

(I changed my mind at least twice while writing this. I was originally going to not support it entirely, but now I'm giving it a try)

werunom commented 6 years ago

I changed my mind at least twice while writing this. :) Thanks for implementing this!

Before I go further, is these snippets included in the update? If yes, how to trigger them? Because, I tried couple of things - \$, \inline, \equation, \math. None of this showed any autocompletion.

Of course, as you mention, using $$ is easy to read the text. But using this along with linter-chktex becomes a pain since chktex keeps underlining these usages. [Of course, I know we can turn off specific warnings; but didnt have patience for that.] So, if a common-user uses a lot of inline equations, chktex fills up the document with warning underlines.

However, regarding the readability of \(equation\), I had implemented the snippet such that there are empty spaces within the equation to make readability better. With this, the text looks like \( equation \). Since latex knows how to handle empty spaces, this indeed improved the readability.

Aerijo commented 6 years ago

@werunom It should happen after a $, with no backslash before it.

Aerijo commented 6 years ago

@werunom You may also need to run the command Autocomplete Latex: Regenerate Completions. I'll look at setting it up so this happens automatically when the completion set (either default or user) changes.

werunom commented 6 years ago

Doing this Autocomplete Latex: Regenerate Completions did the work. Thanks!

PierreMarchand20 commented 6 years ago

May be it would be nice to have variants available too (align*,equation*...). And also:

  1. Display text - \aligned
  2. Should expland to the following
    
    \begin{aligned}

\end{aligned}


3. It is usually used in `align` or `equation` environnement to create blocks (cf. https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics#cite_ref-amsmath_1-9)
3. scope - math
PierreMarchand20 commented 6 years ago

Another idea: \chapter

Aerijo commented 6 years ago

@PierreMarchand20 My current design is to make the second cursor location next to the environment name for things with starred versions (that are reasonably likely to be used). For example, \align expands to

\begin{align$2}
  $1$3
\end{align$2}

This way, the cursor starts in the right place 99% of the time, and it is only a tab press away from enabling the starred version. I've added the equation environment and given it a similar snippet in the latest update. If I've missed any more environments that have starred versions, let me know.

I've also added more sectioning commands, including chapter. They also have the cursor placement for stars, as follows:

\section$2{$1}$3

Also added aligned.

Edit: It's not released yet, but will be in the next one.

MojmirDocekal commented 3 years ago

It would be nice to have a frame: great for making beamer presentations.

  1. display text: \frame

  2. it should expand to

\begin{frame}[]{}

\end{frame}
  1. Usually used in the documentclass beamer

  2. Scope: everywhere.

guger commented 3 years ago

Is there a way to add completions for all greek/math letters?