When I use the package tabularx in a tex file, if I insert table environment, the inner environment will be given as tabularx instead of tabular when the package tabularx is not used.

Normally this would not be a problem for me because I do not deliberately use the package tabularx. However, when I use \documentclasss{memoir}, the package tabularx is automatically used.

I found the variable LaTeX-default-tabular-environment and want to reset its value back to tabular (now I'm not sure it's the correct variable for me to reset),

(eval-after-load 'latex 
    (setq LaTeX-default-tabular-environment "tabular"))

but it does not work, and when I query the value for LaTeX-default-tabular-environment using C-h v, I get the following,

LaTeX-default-tabular-environment is a variable defined in `latex.el'. Its value is "tabularx"

Local in buffer test-tabularx.tex; global value is "tabular"

Automatically becomes buffer-local when set.

Now I am utterly confused. I also tried add some style hook, but it seems to me that I need to alter or update some hook instead just adding it. Could someone help me please? Thanks a lot!

After I put the code by Arash Esbati in my .emacs file, I noticed the following: even if I do not mention memoir in the tex file, for example


(cursor here)

if I then type C-c C-e table RET(a bunch of them), then I would get tabular inside table instead of tabularx inside table. Of course, I later realized that I had another tex file with \documentclass{memoir} loaded in emacs. If I kill that buffer and reboot emacs, everything will be as expected.

1 Answer 1


LaTeX-default-tabular-environment is the variable you want to reset. The hook you are looking for is TeX-update-style-hook:

Documentation: Hook run as soon as style specific hooks were applied.

You can use something like this in your init file:

(eval-after-load "memoir"
  '(add-hook 'TeX-update-style-hook
             (lambda () (setq LaTeX-default-tabular-environment "tabular"))))

AUCTeX style files try to follow the same logic as LaTeX packages regarding loading other packages. AUCTeX has a function TeX-run-style-hooks which is comparable to LaTeX's \RequirePackage macro. I presume that you have this in your .emacs:

(setq TeX-parse-self t)

Now when you load a .tex file like this:

(cursor here)

AUCTeX loads the file memoir.el which contains the following line:

(TeX-run-style-hooks "tabularx")

and next it loads the file tabularx.el containing:

(setq LaTeX-default-tabular-environment "tabularx")

When you have a .tex file like this:

(cursor here)

AUCTeX loads the file tabularx.el directly.

In general, all these changes should be local to the buffer you're working in, other .tex buffers should not be affected.

  • This is great! Just curious, why is this still taking effect even if I do not use the \documentclass{memoir}? For example, I just use \documentclass{memoir} and \usepackage{tabularx} in the preamble.
    – davyjones
    Commented Nov 16, 2017 at 6:46
  • @davyjones - You're welcome. I don't understand your comment, though. How does your document look like? Maybe you can add a minimal .tex example to your question showing the effect you're describing. Commented Nov 16, 2017 at 8:55
  • I added something explanation up in the post. The thing I mentioned above is because I loaded another file of memoir class. But this is still weird, normally emacs+auctex would not recognize packages loaded by another file in another buffer, right?
    – davyjones
    Commented Nov 16, 2017 at 9:53
  • I might have an answer to my curiosity. I just found that he function add-hook admits a fourth argument, which we can set to t. That solves the problem as far as i can test. Many thanks!
    – davyjones
    Commented Nov 16, 2017 at 14:46
  • @davyjones - See my updated answer. Commented Nov 18, 2017 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.