On my way learning emacs and doing some first steps in elisp programming, I'm trying to adapt the LaTeX output of org-export. It's a lot learning by doing and that's a good thing since it improves my skills step by step.

But since some of the functions defined in oy-latex.el are quite complex, it would be great to check the values of some local variables/symbols assigned with let or let* after I modified the code, so I can see if my edits were correct.

For example the function org-latex--caption/label-string assigns the text named with #+caption: in the org-file to the local variable main (using another function org-export-get-caption):

(let* ((label (org-latex--label element info nil t))
       (main (org-export-get-caption element)) ;; this line!
       (attr (org-export-read-attribute :attr_latex element))

How can I check the current value of the symbol/variable main after e.g. I edited the definition. Since the value is only locally assigned and the function is only invoked when I export with C-c C-e l p, I don't know any way to access the value. But it would be of great help to debug my edits and find possible errors.

I'm aware that there might be a simple solution, but couldn't find one so far; mainly due to my very minimal knowledge of emacs lisp. Thus, any help is very appreciated!

(Of course, I do not change anything in the ox-latex.el itself but only in a custom package which is loaded locally.)

  • I am not sure what you mean exactly, but you can always wrap the value with a print, i.e. (print (org-export-get-caption element)). Print does not alter the 'original' return value. Commented Nov 10, 2023 at 11:44
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Commented Nov 10, 2023 at 17:31

1 Answer 1


As you're modifying the code, you have many options.

You can log messages with the C-hf message function. That's super simple. View the *Messages* buffer with C-he.

You can defvar some permanent variable and setq it to the value of the let-bound value while it's still bound, so that you can inspect it later with C-hv.

You could (debug) in the code to drop into the normal debugger at that point, or M-x debug-on-entry for the function, or instrument the function definition for edebug to step through the function when it's called. Regardless of how you debug, you can then inspect values as you step through the code. You can read all about the debuggers in the elisp manual: C-hig (elisp)Debugging RET

  • thanks for the hints. I'll try some of your suggestions. Which way would you prefer personally?
    – lukeflo
    Commented Nov 10, 2023 at 13:06
  • "It depends" -- whichever gets me the result with the least effort basically. Probably either message or using one of the debuggers in practice. Try them all. Using the debuggers is the most complex suggestion, but having a basic familiarity with those is very valuable, so I recommend doing that regardless of the current problem.
    – phils
    Commented Nov 11, 2023 at 4:49
  • @lukeflo If you found phils' answer helpful, you should mark the answer as accepted Commented Nov 14, 2023 at 21:41
  • @PhilHudson I know. I'm still testing the different ways and will share my experience soon.
    – lukeflo
    Commented Nov 15, 2023 at 6:29
  • I find edebug more user friendly than regular debug. It steps through the function showing every value. Nevertheless, it can take some time. Couldn't get it to go with logging the value as message which seems to be the less complicated way. Might have to take a more detailed look into the docs...
    – lukeflo
    Commented Nov 24, 2023 at 18:04

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.