Giter VIP home page Giter VIP logo

Comments (34)

dankessler avatar dankessler commented on June 20, 2024 3

@James-Hanson asks:

Is there a quick fix for this issue at the moment?

One hack is to (painstakingly) duplicate the logic for latex-mode for LaTeX-mode, which is what I originally tried to do in #16283, but it turned out to be more painstaking than I was willing to stomach and so I came up with an upstream fix to bind-map.

I have "fixed" this for myself locally by using the version of bind-map that has my patch (which is currently sitting as a PR).

You can accomplish this by adding this entry to dotspacemacs-additional-packages

     (bind-map :location (recipe
                            :fetcher github
                            :repo "dankessler/emacs-bind-map"
                            :branch "feat-remap-aliased-modes"))

After restarting emacs, if you update packages with SPC f e U, it should offer to update bind-map using my patched version.

I frequently use this approach (of telling spacemacs to use a version of a package that I have patched) whenever I find and fix bugs for packages but am waiting for the PR to be adopted.

Unfortunately, the renaming of latex-mode -> LaTeX-mode has subtle ramifications for many packages that relied on major-mode being precisely equal to latex-mode (e.g., see this PR for {helm,ivy}-bibtex.

PS: the lsp part of this bug report has been resolved thanks to adoption of this PR.

EDIT: added quotes around the repo name; thanks @jajpater for catching that

from spacemacs.

vitaminace33 avatar vitaminace33 commented on June 20, 2024 3

Just here to say that I am expriencing this issue with

  • Emacs 29.2
  • Spacemacs Develop
  • AUCTeX 14.0.3
  • Texlab 5.12.4

I worked around it by downgrading AUCTeX to 13.3.0, which is obviously not a fix, but I depend too much on it.

Regards.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024 2

The issue with lsp would need to be fixed in the upstream package lsp-latex; I'll try to fix it there.

UPDATE: upstream PR is now submitted

from spacemacs.

atreyasha avatar atreyasha commented on June 20, 2024 1

@dankessler thanks a lot for your bind-map patch, it fixes the issue for me:

#16282 (comment)

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024 1

My PR to bind-map has been merged, which fixes the primary complaint that this issue raised.

It sounds like some people (@tigerjack) are having different, but likely closely-related, issues with the newest version of AUCTeX. I'd suggest that we close this issue and open a fresh one to track any of those specific problems.

Also, I'd suggest people remove this hack from their config:

     (bind-map :location (recipe
                            :fetcher github
                            :repo "dankessler/emacs-bind-map"
                            :branch "feat-remap-aliased-modes"))

restart emacs, and then update packages to grab the latest version of bind-map which has this change integrated. You'll then continue to get any new updates from the upstream bind-map

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

After digging into this more, the place for a deeper fix would be upstream and most likely in bind-map, but I'm not even sure it makes sense for it to try to compensate for major mode remapping. The simplest fix is probably to just tweak the latex layer to cover both the old (for people using older emacs/AUCTeX) and new major mode names.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

Do the auctex changes affect also the local variables definition?
While your pull request works inside the main file (that is, TeX-master: t), it does not from other ones (that is, TeX-master: "main").

EDIT: It seems that the TeX-master is properly set when the C-c _ keybinding is invoked, and the following is written into the tex file

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "slides"
%%% End:

However, it is not read again when reopening the file later. May be it due to the fact that the mode is called LaTeX and it is expecting something else? I tried to change it to latex, but the effect is the same.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

@tigerjack the local variable TeX-master seems to be working correctly for me, e.g., if I open a file that has

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "../main"
%%% End:

where there is a main.tex file in the parent directory, then things work properly, e.g., compiling with SPC a u compiles the parent file, not the child file which is open.

Your issue did make me realize that I had missed some keybinds in my PR, e.g., those dealing with reftex features (e.g., SPC R t does not give the reftex-toc overview. To avoid making it too kludgy, I'm going to rework the PR so that at the top of the latex layer's packages.el file, it figures out whether it should set configuration for latex-mode or LaTeX-mode (similarly for tex-mode and context-mode), sets some private variables appropriately, and then relies on those throughout.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

This is a bigger pain than I thought. When packages.el is run, AUCTeX has not yet been loaded, so it's somewhat challenging (to me at least) to figure out whether things should be configured for latex-mode or LaTeX-mode.

Configuring for both does kind of cover our bases, but it makes the code pretty ugly and duplicative. In addition, if dotspacemacs/user-config sets key bindings (e.g., I use (spacemacs/set-leader-keys-for-major-mode 'latex-mode "oc" 'cdlatex-mode)), then that config would need to get updated (or duplicated) too.

Instead, I'm now of the opinion that it'd be cleaner for bind-map to be updated so that it is aware of major-mode-remap-alist. For example, suppose I have configured keybindings for foo-mode, but foo-mode has been remapped to Foo-mode. If Foo-mode is activated (either directly or on redirecton from foo-mode then I want bind-map to activate my bindings for foo-mode. Chaos might abound if I've configured two different keymaps for foo-map and Foo-map and remapped foo-map to Foo-map, but that seems like a configuration that is asking for trouble anyway.

I've locally patched bind-map to behave as described above and it's working for me, so in due course I'll open that as a PR upstream.

In related news, my fix to lsp-latex was merged, so that part of the issue is now resolved.

I'm going to leave this issue open and its associated PR in draft status for now, because if we can get bind-map changed then this issue is resolved and the PR is moot, but if for whatever reason that doesn't work then we can try to work around it in spacemacs.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

I have opened a PR against bind-map that should hopefully fix these issues without requiring further modifications to spacemacs.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

@tigerjack the local variable TeX-master seems to be working correctly for me, e.g., if I open a file that has

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "../main"
%%% End:

where there is a main.tex file in the parent directory, then things work properly, e.g., compiling with SPC a u compiles the parent file, not the child file which is open.

Your issue did make me realize that I had missed some keybinds in my PR, e.g., those dealing with reftex features (e.g., SPC R t does not give the reftex-toc overview. To avoid making it too kludgy, I'm going to rework the PR so that at the top of the latex layer's packages.el file, it figures out whether it should set configuration for latex-mode or LaTeX-mode (similarly for tex-mode and context-mode), sets some private variables appropriately, and then relies on those throughout.

I am not sure of what's happening behind the scenes to be honest. It seems that some files are opened in LaTeX/PS major mode, while others in TeX or TeX/PS. In the latter, the local variables are not updated.

When I try to force the activation of the LaTeX major mode and revert the buffer, the mode seems to be applied, but I get another error from helm saying helm-M-x-execute-command: Cannot open load file: No such file or directory, tex-buf. And of course the local variables are not update either.

On the other hand, if I do a C-c _ to set the master, the TeX-master variable is correctly applied.

I am still unsure if the behaviour is related to the auctex update, but I did not have this issue before. If you need some testing, I will be glad to help.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

@tigerjack I suspect the issue is with the way your major-modes are getting specified. If I understand correctly, in the new version of AUCTeX, TeX-mode isn't really a mode you should ever be in explicitly. From the "Changes" section of the AUCTeX manual:

          Note that ‘TeX-mode’ isn't meant for use for end users.  It is
          only meant for the base mode for other major modes.  Its role
          is to provide base keymap, hook and syntax table under the
          same name with the former AUCTeX and run the common
          initialization code.

Can you confirm which version of AUCTeX you are using with SPC h d v auctex-version RET?

My understanding of the way AUCTeX handles mode mapping (with new AUCTeX and emacs 29+) is as follows.

  1. Open a file that ends with .tex
  2. There is an entry in auto-mode-alist that maps this (via regexp) to tex-mode
  3. An entry in major-mode-remap-alist remaps tex-mode to TeX-tex-mode
  4. Per its documentation, TeX-tex-mode is essentially a virtual mode that tries to guess the appropriate mode to activate

When you somehow land in TeX-mode, something has presumably gone wrong in one of these steps. I suspect it's happened in step 4, but I can't be sure. If I were you, I'd look at the documentation for TeX-tex-mode (with SPC h d f TeX-tex-mode RET) to understand how it chooses which mode to activate based on various logic and variables, and you can see if you can understand why you're not landing in LaTeX-mode.

from spacemacs.

James-Hanson avatar James-Hanson commented on June 20, 2024

Is there a quick fix for this issue at the moment?

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

Can you confirm which version of AUCTeX you are using with SPC h d v auctex-version RET?

Its value is "14.0.2"

My understanding of the way AUCTeX handles mode mapping (with new AUCTeX and emacs 29+) is as follows. [...]

I suspect it was related to a failure of the undo-tree history (a similar error is reported here).

Despite that, even if I force the LaTeX-mode, the TeX-master variable keeps having the value t instead of main.
The same thing happens with a file for which the LaTeX-mode is enabled automatically.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

Upon further investigation, the problem seems to be related to this line of my configuration file

(add-hook 'LaTeX-mode-hook #'latex-extra-mode)

So I think it's a bug of the latex-extra-mode

EDIT: I fixed this error here Malabarba/latex-extra#38

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

@dankessler @James-Hanson
Upon further usage, I think an easy workaround would be to either declare buffer or directory variables. Let me know if it works for you as well.

File variable

Inside the .tex file, declare the following

%%% Local Variables: 
%%% mode: LaTeX
%%% End: 

Directory variable

Create a .dir-locals.el file in the directory where your .tex files are, and put the following content.

((latex-mode
  (mode . LaTeX )))

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

Upon further investigation, the problem seems to be related to this line of my configuration file

(add-hook 'LaTeX-mode-hook #'latex-extra-mode)

So I think it's a bug of the latex-extra-mode

EDIT: I fixed this error here Malabarba/latex-extra#38

@tigerjack glad you got it sorted out and were able to submit a fix upstream

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

File variable

Inside the .tex file, declare the following

%%% Local Variables: 
%%% mode: LaTeX
%%% End: 

Directory variable

Create a .dir-locals.el file in the directory where your .tex files are, and put the following content.

((latex-mode
  (mode . LaTeX )))

@tigerjack I'm a little surprised that this works for you, because I would expect that after the mode becomes LaTeX-mode, then the change-major-mode-after-body-hook fires, which causes bind-map to decide that you're not in latex-mode anymore, set spacemacs-latex-mode-map-active to nil, and disable all of the spacemacs-provided bindings.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

@dankessler I honestly don't know what is the sequence of instructions that leads to this behaviour. What I can add, that maybe can help you in debugging the issue, is

  1. The effect seems to be the same either if I put latex or LaTeX
  2. The snippets are working
  3. The compilation process (either C-c C-c xelatex or , b) works, but it opens in a tex-shell buffer. C-c C-l command does not seem to work properly, and the C-c ` is undefined.
  4. , v to visualize the output pdf file works only after the first compilation, even if the pdf file is already present.

Let me know if I can help in any other way.

from spacemacs.

jajpater avatar jajpater commented on June 20, 2024

Also a big thanks from me. It indeed fixes the issue for me. I had to add quotation marks to the repo part:

(bind-map :location (recipe :fetcher github :repo "dankessler/emacs-bind-map" :branch "feat-remap-aliased-modes"))

from spacemacs.

James-Hanson avatar James-Hanson commented on June 20, 2024

@dankessler Thank you for the help, but it doesn't seem to be changing anything for me. I also tried it with quotes around the repo.

Is there some way to check to see if the version of bind-map my installation is using is actually your branch? I'm not seeing anything helpful in list-packages and I'm not seeing anything in the messages buffer indicating that it's actually pulling your branch.

I realized I was trying to do this with Emacs 28.2. I built 29.2 and was able to get it to work. Thanks again.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

@dankessler Thank you for the help, but it doesn't seem to be changing anything for me. I also tried it with quotes around the repo.

Is there some way to check to see if the version of bind-map my installation is using is actually your branch? I'm not seeing anything helpful in list-packages and I'm not seeing anything in the messages buffer indicating that it's actually pulling your branch.

I realized I was trying to do this with Emacs 28.2. I built 29.2 and was able to get it to work. Thanks again.

@James-Hanson thanks for letting me know and for sharing this update. I thought my fix would work for emacs 28, too, so I may take a slightly closer look to see if I can adjust the patch accordingly.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

Also a big thanks from me. It indeed fixes the issue for me. I had to add quotation marks to the repo part:

(bind-map :location (recipe :fetcher github :repo "dankessler/emacs-bind-map" :branch "feat-remap-aliased-modes"))

@jajpater thanks for noticing that! For whatever reason, it works for me without quotes, but it looks like surrounding with quotes is indeed the idiomatic way to specify recipes. I'll updated my earlier comment to use quotes for anyone who is copy-pasting it.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

@tigerjack the local variable TeX-master seems to be working correctly for me, e.g., if I open a file that has

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "../main"
%%% End:

where there is a main.tex file in the parent directory, then things work properly, e.g., compiling with SPC a u compiles the parent file, not the child file which is open.

I am coming back on this again. In my case, while the SPC m a combination works well, the SPC m v returns the error message Output file "main" does not exist even if the file "main.pdf" exists. However, if I first build and then view, the error goes away. Am I the only one affected by this problem?

from spacemacs.

LailaElbeheiry1 avatar LailaElbeheiry1 commented on June 20, 2024

Just here to say that I am expriencing this issue with

  • Emacs 29.2
  • Spacemacs Develop
  • AUCTeX 14.0.3
  • Texlab 5.12.4

I worked around it by downgrading AUCTeX to 13.3.0, which is obviously not a fix, but I depend too much on it.

Regards.

Can you explain how you downgraded AUCTeX?

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

Even though I do not find any latex-related change in the latest emacs version (29.3), the upgrade nonetheless fixed all my problems when used with auctex 14.0.3.2024-03-17

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

Even though I do not find any latex-related change in the latest emacs version (29.3), the upgrade nonetheless fixed all my problems when used with auctex 14.0.3.2024-03-17

In brief, this is because auctex renamed many of its major modes, e.g., latex-mode -> LaTeX-mode. If emacs >= 29, it uses major-mode-remap-alist in order to register this remapping. However, bind-map, which spacemacs relies on to handle much of its keymapping, was not aware of major-mode-remap-alist. I fixed that in a recent PR, so that now bind-map will activate keymaps for latex-mode when LaTeX-mode is activated provided this remapping was registered in major-mode-remap-alist.

However, AFAIK, bind-map has not been patched to be aware of the way that auctex registers the remapping for emacs < 29, which is probably why things don't work correctly if user emacs < 29.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

@dankessler yes, I was on board with all these problems on 29.2 :)

However, I was still experiencing strange behaviour that you couldn't reproduce (as an example, , v to visualize the PDF output was not working when opening the .tex file, even though the PDF was there. However, building the document using , b was then making the , v shortcut to function).

Today's upgrade to emacs 29.3 fixed those strange behaviours as far as I can tell; maybe it was simply due to a recompilation of all the packages?!. On the other hand, opening .tex files now require considerable more time.

from spacemacs.

dankessler avatar dankessler commented on June 20, 2024

@dankessler yes, I was on board with all these problems on 29.2 :)

Good; sorry for over-explaining :)

However, I was still experiencing strange behaviour that you couldn't reproduce (as an example, , v to visualize the PDF output was not working when opening the .tex file, even though the PDF was there. However, building the document using , b was then making the , v shortcut to function).

Today's upgrade to emacs 29.3 fixed those strange behaviours as far as I can tell; maybe it was simply due to a recompilation of all the packages?!. On the other hand, opening .tex files now require considerable more time.

Interesting! I'm on emacs 29.1 and not encountering any issues, but glad that upgrading to 29.3 fixed things for you!

from spacemacs.

zzjjzzgggg avatar zzjjzzgggg commented on June 20, 2024

A tex file uses \input to include another tex file. Moving the cursor to the included file name, and pressing SPC f f, I find that emacs cannot automatically select the included file, which is not the case before auctex being updated. Does anyone also suffer from this issue?

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

A tex file uses \input to include another tex file. Moving the cursor to the included file name, and pressing SPC f f, I find that emacs cannot automatically select the included file, which is not the case before auctex being updated. Does anyone also suffer from this issue?

I never used this shortcut, and I don't have it in my key bindings. What is the command executed?

from spacemacs.

zzjjzzgggg avatar zzjjzzgggg commented on June 20, 2024

SPC f f runs the command spacemacs/counsel-find-file.

from spacemacs.

tigerjack avatar tigerjack commented on June 20, 2024

@zzjjzzgggg which is an Ivy command. I never used it, nor it. But in theory, you should be able to use [ f for find-file-at-point. I tried it, and while it works on the scratch buffer, it does not work inside a latex buffer. I wonder if Ivy uses find-file-at-point internally.

from spacemacs.

smile13241324 avatar smile13241324 commented on June 20, 2024

I have worked a bit with my latex layer and it seems that with the many fixes from @dankessler this issue is obsolete now. If you run into other strange behaviors please open a new issue for them and I am sure folks will have a look at it.

from spacemacs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.