Re: LaTeX, long line, and synctex.

2023-05-10 Thread Hongyi Zhao
On Thu, May 11, 2023 at 10:54 AM Hongyi Zhao  wrote:
>
> Hi here,
>
> When working with AUCTeX, if I have long-lines in LaTeX file, then the
> SyncTeX positioning will not so accurate. How to tackle this problem?

It seems that the only feasible way is to use `M-q ( fill-paragraph )`
to do the trick.

Regards,
Zhao



LaTeX, long line, and synctex.

2023-05-10 Thread Hongyi Zhao
Hi here,

When working with AUCTeX, if I have long-lines in LaTeX file, then the
SyncTeX positioning will not so accurate. How to tackle this problem?

Regards,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao 
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



Re: Outline based LaTeX source code navigation.

2023-05-10 Thread Hongyi Zhao
On Thu, May 11, 2023 at 12:40 AM Arash Esbati  wrote:
>
> Hongyi Zhao  writes:
>
> > I've added the following setting into my init.el according to the above 
> > guide:
> >
> >  (setq TeX-outline-extra
> >   '(("[ \t]*\\(bib\\)?item\\b" 7)
> > ("bibliography\\b" 2)))
>
> Here is what I tried:
>
>  • emacs -Q
>  • Activated AUCTeX with 0 configuration
>  • Eval'ed the code above in scratch
>  • Opened the file ltnews36.tex
>  • M-x outline-minor-mode RET
>  • C-c @ C-t
>
> and it looks like this:
>
> You should really start sending recipes starting with 'emacs -Q' in
> order to help people understanding your problems.

Thanks, I'll check it out.

> Best, Arash

Regards,
Zhao



master da28858e: Improve handling of beamer class options

2023-05-10 Thread Arash Esbati
branch: master
commit da28858e46013d6cf36acf33a6fad1c6ee08c170
Author: Arash Esbati 
Commit: Arash Esbati 

Improve handling of beamer class options

* style/beamer.el (LaTeX-beamer-class-options-list): New variable
containing the class options.
(LaTeX-beamer-class-options): Use the new variable.
---
 style/beamer.el | 45 -
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/style/beamer.el b/style/beamer.el
index 765519b9..d0d2e627 100644
--- a/style/beamer.el
+++ b/style/beamer.el
@@ -1,6 +1,6 @@
 ;;; beamer.el --- AUCTeX style for the latex-beamer class  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2003-2022  Free Software Foundation, Inc.
+;; Copyright (C) 2003-2023  Free Software Foundation, Inc.
 
 ;; Author: Thomas Baumann 
 ;; Maintainer: auctex-devel@gnu.org
@@ -37,6 +37,9 @@
 (declare-function font-latex-add-keywords
   "font-latex"
   (keywords class))
+(defvar LaTeX-hyperref-package-options-list)
+(defvar LaTeX-color-package-options)
+(defvar LaTeX-xcolor-package-options)
 
 (defun LaTeX-beamer-after-insert-env (env start _end)
   "Do beamer-specific stuff after the insertion of an environment."
@@ -608,22 +611,30 @@ also be a string.  Then the length of the string is used."
 (and (fboundp 'reftex-notice-new-section)
  (reftex-notice-new-section
 
+(defvar LaTeX-beamer-class-options-list
+  (progn
+(TeX-load-style "hyperref")
+(TeX-load-style "color")
+(TeX-load-style "xcolor")
+`(("usepdftitle" ("false")) ("envcountsect")
+  ("notheorems") ("noamsthm") ("compress") ("t") ("c")
+  ("leqno") ("fleqn") ("handout") ("trans")
+  ("ignorenonframetext") ("onlytextwidth")
+  ("noamssymb") ("bigger") ("smaller") ("8pt") ("9pt")
+  ("10pt") ("11pt") ("12pt") ("14pt") ("17pt") ("20pt")
+  ("draft") ("CJK") ("cjk") ("pgf")
+  ;; Take only the keys from `LaTeX-hyperref-package-options-list'
+  ;; since a new alist doesn't make sense here and isn't
+  ;; recognized as such:
+  ("hyperref" ,(mapcar #'car LaTeX-hyperref-package-options-list))
+  ("color" ,LaTeX-color-package-options)
+  ("xcolor" ,LaTeX-xcolor-package-options)
+  ("ucs") ("utf8x") ("utf8")
+  ("aspectratio" ("2013" "1610" "169" "149" "141" "54" "43" "32"
+  "Class options for the beamer class.")
+
 (defun LaTeX-beamer-class-options ()
-  "Read the beamer class options from the user."
-  (TeX-load-style "hyperref")
-  (TeX-load-style "color")
-  (TeX-load-style "xcolor")
-  (TeX-read-key-val t '(("usepdftitle" ("false")) ("envcountsect")
-("notheorems") ("noamsthm") ("compress") ("t") ("c")
-("leqno") ("fleqn") ("handout") ("trans")
-("ignorenonframetext") ("onlytextwidth")
-("noamssymb") ("bigger") ("smaller") ("8pt") ("9pt")
-("10pt") ("11pt") ("12pt") ("14pt") ("17pt") ("20pt")
-("draft") ("CJK") ("cjk") ("pgf")
-("hyperref" LaTeX-hyperref-package-options-list)
-("color" LaTeX-color-package-options)
-("xcolor" LaTeX-xcolor-package-options)
-("ucs") ("utf8x") ("utf8")
-("aspectratio" ("2013" "1610" "169" "149" "141" "54" 
"43" "32")
+  "Prompt for the class options for the beamer class."
+  (TeX-read-key-val t LaTeX-beamer-class-options-list))
 
 ;;; beamer.el ends here



Re: Outline based LaTeX source code navigation.

2023-05-10 Thread Arash Esbati
Hongyi Zhao  writes:

> I've added the following setting into my init.el according to the above guide:
>
>  (setq TeX-outline-extra
>   '(("[ \t]*\\(bib\\)?item\\b" 7)
> ("bibliography\\b" 2)))

Here is what I tried:

 • emacs -Q
 • Activated AUCTeX with 0 configuration
 • Eval'ed the code above in scratch
 • Opened the file ltnews36.tex
 • M-x outline-minor-mode RET
 • C-c @ C-t

and it looks like this:

You should really start sending recipes starting with 'emacs -Q' in
order to help people understanding your problems.

Best, Arash


Soft wrap (again?)

2023-05-10 Thread Sergio Callegari

Hi,

I know that the matter has been discussed in the past (e.g., 
https://lists.gnu.org/archive/html/auctex/2012-01/msg00025.html), 
however looking at those past discussions I could not find a solution to 
my specific problem, so please take my apology in advance for re-opening 
the topic.


I am not interested in opinions on what one should use or the relative 
merits of hard wrap over soft wrap or viceversa. Independently of this 
(and even of my own preferences) I often need to cooperate with other 
people who use tools based on the soft wrap approach (e.g. TeXStudio or 
the online Overleaf editor) and follow their choices. Basically this 
means that I often need to use soft wrap too.


In Emacs, using soft wrap means disabling auto-fill, rewiring your brain 
so that you do not press "ESC q" mechanically, and enabling the 
visual-line-mode. Even with this you miss all the nice indentation that 
auctex provides, though. You can get a bit closer to it by enabling the 
adaptive-wrap-prefix-mode. This is more or less what I found in the 
previous exchanges.


However, I still miss one thing: the adaptive-wrap does not seem to 
understand braces. Hence, when some "macro argument" gets wrapped, it 
gets no indentation. For instance, I get


\section{This is a rather long section name that
gets wrapped}

and not

\section{This is a rather long section name that
  gets wrapped}

The same goes with \emph, \foreignlanguage, \textbf, etc. Particularly 
when things get nested it becomes a burden to check where the arguments 
end and whether the braces are matched.


So my question is: are auctex and adaptive-wrap-prefix-mode two 
completely independent packages, or is it possible for auctex to use its 
"understanding" of LaTeX to provide hints to adaptive-wrap-prefix-mode 
about the amount of spaces to use in the prefix for each soft wrapped line?


Thanks and best regards,

Sergio




Re: Outline based LaTeX source code navigation.

2023-05-10 Thread Arash Esbati
Hongyi Zhao  writes:

> I tried it but out got a menu with so many options. In fact, I wonder
> whether I can just obtain the outline, e.g., like the one shown in
> pdf-tools mode, which is more concise and intuitive to use with the
> toc as the titles of the outline?

`reftex-toc' comes to my mind, but that is already recommended.

Best, Arash



Re: Improving fontification support for biblatex qualified citation lists

2023-05-10 Thread Gustavo Barros
Hi Arash,

On Wed, 10 May 2023 at 07:35, Arash Esbati  wrote:

> Thanks for looking at this and your ideas about this issue.  To be
> honest, I'm not convinced that we should go through this only in order
> to get cite lists working.  The benefits for some macros provided by one
> single package, namely biblatex, seem too low to me.  We have a
> non-perfect solution now, but I guess we can live with it.  Why do need
> the fontification, jinx?

Thanks for looking into this.

Well, I've long yearned for a better fontification for them (you may
recall: https://tex.stackexchange.com/q/425883). I am a regular user
of citation lists, and frequently long ones at that.

However, yes, now I'm using Jinx, and fontification became
"functional" besides the eye candy. And indeed that's why I'm looking
into this. Truth be told though that Jinx excludes
`font-lock-variable-name-face' meaning the optional arguments of
citation commands are not spell checked
(https://github.com/minad/jinx/issues/25), so I'd need special
treatment for these macros anyway. Thus, I really proposed this
because it seemed simple enough and a fontification improvement.

For the purposes of Jinx I cooked a function akin to
`font-latex-match-command-with-arguments' which handles unlimited
number of arguments and also instructs Jinx to spell check the
optional arguments (under my setup). It is not too complicated either.
Btw, I did send you that message in that Jinx thread in emacs-devel
about the use of faces to handle spell checking exclusion
(https://lists.gnu.org/archive/html/emacs-devel/2023-04/msg00512.html,
though perhaps that thread was not the best place for me to chime in).
And I'm still hoping someone will get interested in this. It is a
really powerful and appealing approach for the problem. Not almighty,
not without its own set of issues, but very promising. And, as I said
there, there's no reason to assume it couldn't be used by the built-in
spell checking packages. I'm still playing with that stuff, and I'd be
happy to discuss and share if there's interest.

Best,
Gustavo.



Re: Outline based LaTeX source code navigation.

2023-05-10 Thread Hongyi Zhao
On Wed, May 10, 2023 at 3:58 PM Arash Esbati  wrote:
>
> Hongyi Zhao  writes:
>
> > But I still cannot figure out how to use the method described here:
> > https://www.gnu.org/software/auctex/manual/auctex/Outline.html
>
> Did you try 'M-x outline-minor-mode RET' as described here:

I tried it but out got a menu with so many options. In fact, I wonder
whether I can just obtain the outline, e.g., like the one shown in
pdf-tools mode, which is more concise and intuitive to use with the
toc as the titles of the outline?

>   
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Mode.html#Outline-Mode
>
> This page is linked in the AUCTeX manual page you mentioned above.
>
> Best, Arash

Regards,
Zhao



Re: Improving fontification support for biblatex qualified citation lists

2023-05-10 Thread Arash Esbati
Hi Gustavo,

Gustavo Barros  writes:

> The problem here is that the bibkeys of biblatex's citation lists are
> not really mandatory, and yet they are given in braces.  But we could
> extend the syntax of `font-latex.el' to accommodate this case.  We
> could use, for example, a closing brace to indicate an optional
> argument in braces.  With that, in
> `font-latex-match-command-with-arguments' which handles the
> fontification of such commands, we could have (around were the
> `alternative' is dealt with):
>
> #+begin_src emacs-lisp
> (when (eq spec ?})
>   (setq opt-braces t)
>   (setq spec ?{))
> #+end_src
>
>
> And then, when the syntax-error is handled for the mandatory argument case:
>
> #+begin_src emacs-lisp
> (unless (or alternative opt-braces)
>   (setq syntax-error t)
>   (when (and match-beg (= match-beg (point)))
> (setq error-indicator-pos match-beg))
>   (throw 'break nil))
> #+end_src

Thanks for looking at this and your ideas about this issue.  To be
honest, I'm not convinced that we should go through this only in order
to get cite lists working.  The benefits for some macros provided by one
single package, namely biblatex, seem too low to me.  We have a
non-perfect solution now, but I guess we can live with it.  Why do need
the fontification, jinx?

What do others think?

Best, Arash



bug#63396: \foreignlanguage in babel style file

2023-05-10 Thread Arash Esbati
Gustavo Barros  writes:

> Yes, very much so. Thank you!

Thanks for your response.  I installed that change (commit c9ab5d58)
incl. some other minor issues I found.  Closing this report.

Best, Arash



___
bug-auctex mailing list
bug-auctex@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-auctex


master c9ab5d58: Update style/babel.el to package version 3.88

2023-05-10 Thread Arash Esbati
branch: master
commit c9ab5d58f327c759a23f7f6b8618383b2822dcdc
Author: Arash Esbati 
Commit: Arash Esbati 

Update style/babel.el to package version 3.88

* style/babel.el ("babel"): Add support for optional argument for
\foreignlanguage macro and otherlanguage* environment.
Change the keywords class for \foreignlanguage to `textual'.
(bug#63396)
(LaTeX-babel-package-options-list): Update package options.
---
 style/babel.el | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/style/babel.el b/style/babel.el
index 2483b73b..495e9f64 100644
--- a/style/babel.el
+++ b/style/babel.el
@@ -1,4 +1,4 @@
-;;; babel.el --- AUCTeX style for `babel.sty' version 3.31.  -*- 
lexical-binding: t; -*-
+;;; babel.el --- AUCTeX style for `babel.sty' version 3.88.  -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2005-2023  Free Software Foundation, Inc.
 
@@ -26,7 +26,7 @@
 
 ;;; Commentary:
 
-;; This file adds support for `babel.sty' version 3.31 from 2019/05/04.
+;; This file adds support for `babel.sty' version 3.88 from 2023/04/18.
 
 ;;; Code:
 
@@ -256,6 +256,7 @@
   (TeX-arg-completing-read (LaTeX-babel-active-languages)
"Language"))
 '("foreignlanguage"
+  [TeX-arg-completing-read-multiple ("date" "captions")]
   (TeX-arg-completing-read (LaTeX-babel-active-languages)
"Language")
   t)
@@ -364,6 +365,7 @@
   (TeX-arg-completing-read (LaTeX-babel-active-languages)
"Language"))
 '("otherlanguage*" LaTeX-env-args
+  [TeX-arg-completing-read-multiple ("date" "captions")]
   (TeX-arg-completing-read (LaTeX-babel-active-languages)
"Language"))
 '("hyphenrules" LaTeX-env-args
@@ -374,7 +376,6 @@
(when (and (featurep 'font-latex)
   (eq TeX-install-font-lock 'font-latex-setup))
  (font-latex-add-keywords '(("selectlanguage" "{")
-("foreignlanguage""{{")
 ("babeltags"  "{")
 ("babelensure""{{")
 ("shorthandon""{")
@@ -394,7 +395,9 @@
  (font-latex-add-keywords '(("defineshorthand""[{{")
 ("aliasshorthand" "{{")
 ("languageattribute"  "{{"))
-  'variable)))
+  'variable)
+ (font-latex-add-keywords '(("foreignlanguage""[{{"))
+  'textual)))
  TeX-dialect)
 
 (defvar LaTeX-babel-package-options-list
@@ -426,6 +429,9 @@
("layout" ("sectioning" "counters" "lists"
   "contents" "footnotes"  "captions"
   "columns" "graphics" "extras"))
+   ("provide" ("*"))
+   ("provide+" ("*"))
+   ("provide*" ("*"))
("base"))
  (mapcar #'list LaTeX-babel-language-list)))
   "Package options for the babel package.")



bug#63396: \foreignlanguage in babel style file

2023-05-10 Thread Gustavo Barros
Hi Arash,

On Wed, 10 May 2023 at 04:46, Arash Esbati  wrote:

> Thanks for the report.  You were thinking about a change like this?
>
> --8<---cut here---start->8---
> diff --git a/style/babel.el b/style/babel.el
> index 2483b73b..2110289b 100644
> --- a/style/babel.el
> +++ b/style/babel.el
> @@ -256,6 +256,7 @@
>(TeX-arg-completing-read (LaTeX-babel-active-languages)
> "Language"))
>  '("foreignlanguage"
> +  [TeX-arg-completing-read-multiple ("date" "captions")]
>(TeX-arg-completing-read (LaTeX-babel-active-languages)
> "Language")
>t)
> @@ -374,7 +375,6 @@
> (when (and (featurep 'font-latex)
>(eq TeX-install-font-lock 'font-latex-setup))
>   (font-latex-add-keywords '(("selectlanguage" "{")
> -("foreignlanguage""{{")
>  ("babeltags"  "{")
>  ("babelensure""{{")
>  ("shorthandon""{")
> @@ -394,7 +394,9 @@
>   (font-latex-add-keywords '(("defineshorthand""[{{")
>  ("aliasshorthand" "{{")
>  ("languageattribute"  "{{"))
> -  'variable)))
> +  'variable)
> + (font-latex-add-keywords '(("foreignlanguage""[{{"))
> +  'textual)))
>   TeX-dialect)
>
>  (defvar LaTeX-babel-package-options-list
> --8<---cut here---end--->8---

Yes, very much so. Thank you!

Best,
Gustavo.



___
bug-auctex mailing list
bug-auctex@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-auctex


Re: Outline based LaTeX source code navigation.

2023-05-10 Thread Arash Esbati
Hongyi Zhao  writes:

> But I still cannot figure out how to use the method described here:
> https://www.gnu.org/software/auctex/manual/auctex/Outline.html

Did you try 'M-x outline-minor-mode RET' as described here:

  
https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Mode.html#Outline-Mode

This page is linked in the AUCTeX manual page you mentioned above.

Best, Arash



bug#63396: \foreignlanguage in babel style file

2023-05-10 Thread Arash Esbati
Hi Gustavo,

Gustavo Barros  writes:

> just a quick and simple one.
>
> `\foreignlanguage' specs in `babel.el' are missing the optional
> argument it takes, both in `TeX-add-symbol` and in
> `font-latex-add-keywords`.
>
> Also, `\foreignlanguage' is included in the `function' font-lock
> class. Arguably `textual' would be a much better fit for it.

Thanks for the report.  You were thinking about a change like this?

--8<---cut here---start->8---
diff --git a/style/babel.el b/style/babel.el
index 2483b73b..2110289b 100644
--- a/style/babel.el
+++ b/style/babel.el
@@ -256,6 +256,7 @@
   (TeX-arg-completing-read (LaTeX-babel-active-languages)
"Language"))
 '("foreignlanguage"
+  [TeX-arg-completing-read-multiple ("date" "captions")]
   (TeX-arg-completing-read (LaTeX-babel-active-languages)
"Language")
   t)
@@ -374,7 +375,6 @@
(when (and (featurep 'font-latex)
   (eq TeX-install-font-lock 'font-latex-setup))
  (font-latex-add-keywords '(("selectlanguage" "{")
-("foreignlanguage""{{")
 ("babeltags"  "{")
 ("babelensure""{{")
 ("shorthandon""{")
@@ -394,7 +394,9 @@
  (font-latex-add-keywords '(("defineshorthand""[{{")
 ("aliasshorthand" "{{")
 ("languageattribute"  "{{"))
-  'variable)))
+  'variable)
+ (font-latex-add-keywords '(("foreignlanguage""[{{"))
+  'textual)))
  TeX-dialect)

 (defvar LaTeX-babel-package-options-list
--8<---cut here---end--->8---

Best, Arash



___
bug-auctex mailing list
bug-auctex@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-auctex


Re: font-latex.el: Introducing new keyword class 'function-noarg'

2023-05-10 Thread Arash Esbati
Hi Keita,

Ikumi Keita  writes:

> I'm neutral to that idea, but it won't do particular harm. So I'm fine
> if you install it.

Thanks for your response; installed with commit 93fa8bde57.

Best, Arash



In-buffer completion for package names and options

2023-05-10 Thread Arash Esbati
Hi all,

I think I have a working setup for in-buffer completion of arguments of
\usepackage and/or \RequirePackage.  It needed some preparation (commit
28aa6b99e4) but it seems to work.  I could apply the same idea to
\documentclass.

Patch is attached.  Any comments welcome.

Best, Arash
diff --git a/latex.el b/latex.el
index cf2518b2..0db89aed 100644
--- a/latex.el
+++ b/latex.el
@@ -7597,6 +7597,76 @@ COLLECTION is an list of strings."
(lambda (_)
  collection)
 
+(defvar LaTeX--completion-global-package-files nil
+  "List of LaTeX package files for in-buffer completion.
+Initialized once at the first time in-buffer completion for a
+package name is requested.  May be reset with
+`\\[universal-argument] \\[TeX-normal-mode]'.  Note that this
+variable exists in parallel with `LaTeX-global-package-files'
+which cannot be used for the purposes of in-buffer completion
+without breaking the setting of `TeX-arg-input-file-search'.")
+
+;; Add the variable to `TeX-normal-mode-reset-list':
+(add-to-list 'TeX-normal-mode-reset-list
+ 'LaTeX--completion-global-package-files)
+
+(defun LaTeX-completion-candidates-usepackage (entry)
+  "Return completion candidates for arguments of \\usepackage macro.
+ENTRY is the value returned by `LaTeX-what-macro'.  This function
+provides completion for package names if point is inside the
+mandatory argument and package options if inside the first
+optional argument."
+  (cond ((eq (nth 3 entry) 'mandatory)
+ (unless LaTeX--completion-global-package-files
+   (let ((TeX-file-extensions '("sty")))
+ (message "Searching for LaTeX packages...")
+ (setq LaTeX--completion-global-package-files
+   (TeX-search-files-by-type 'texinputs 'global t t))
+ (message "Searching for LaTeX packages...done")))
+ (LaTeX-completion-candidates-completing-read-multiple
+  LaTeX--completion-global-package-files))
+;; We have to be more careful for the optional argument since
+;; the macro can look like this:
+;; \usepackage[opt1]{mand}[opt2].  So we add an extra check if
+;; we inside the first optional arg:
+((and (eq (nth 3 entry) 'optional)
+  (= (nth 2 entry) 1))
+ (let ((syntax (TeX-search-syntax-table ?\[ ?\]))
+   package package-opts)
+   ;; We have to find out about the package name:
+   (save-excursion
+ (with-syntax-table syntax
+   (condition-case nil
+   (let ((forward-sexp-function nil))
+ (up-list))
+ (error nil)))
+ (skip-chars-forward "^[:alnum:]")
+ (setq package (thing-at-point 'symbol t)))
+   ;; Load the style file; may fail but that's Ok for us
+   (TeX-load-style package)
+   ;; Now we have to find out how the options are available:
+   ;; This is usually a variable called
+   ;; `LaTeX--package-options'.  If it is a function,
+   ;; then the options are stored either in a variable or a
+   ;; function called `LaTeX--package-options-list:'
+   (when (setq package-opts
+   (intern-soft (format "LaTeX-%s-package-options" package)))
+ (cond ((and (boundp package-opts)
+ (symbol-value package-opts))
+(LaTeX-completion-candidates-completing-read-multiple
+ (symbol-value package-opts)))
+   ((and (setq package-opts
+   (intern-soft (format "LaTeX-%s-package-options-list" package)))
+ (boundp package-opts)
+ (symbol-value package-opts))
+(LaTeX-completion-candidates-key-val
+ (symbol-value package-opts)))
+   ((fboundp package-opts)
+(LaTeX-completion-candidates-key-val
+ (funcall package-opts)))
+   (t nil)
+(t nil)))
+
 (defun LaTeX-completion-parse-args (entry)
   "Return the match of buffer position ENTRY with AUCTeX macro definitions.
 ENTRY is generated by the function `LaTeX-what-macro'.  This
@@ -7811,7 +7881,10 @@ function `TeX--completion-at-point' which should come first in
   (when (and (LaTeX-completion-find-argument-boundries)
  (not (nth 4 (syntax-ppss
 (let ((entry (LaTeX-what-macro)))
-  (cond ((or (and entry
+  (cond ((and entry
+  (member (car entry) '("usepackage" "RequirePackage")))
+ (LaTeX-completion-candidates-usepackage entry))
+((or (and entry
   (eq (nth 1 entry) 'mac)
   (assoc (car entry) (TeX-symbol-list)))
  (and entry