Sebastian P. Luque writes: > This is great, and very interesting to learn about the BIND keyword. > > Thank you,
You're welcome. Of course, if you use the filter very often, it is not necessary to include it in a document or use the bind keyword. It would be enough to add the function to your init and the line: (add-to-list 'org-export-filter-final-output-functions #'caption-auto-width) In a case like this, however, I would prefer to use the other function in Lua within LuaTeX, since two commands could be defined: one to enable the automatic caption width and one to disable it, throughout the document. E.g.: #+begin_src latex \usepackage{luacode} \begin{luacode*} function caption_width ( text ) text = string.gsub ( text, "(\\includegraphics.+)", "\\sbox0{%1}") text = string.gsub ( text, "(\\caption.+)", "\\begin{minipage}{\\wd0}\\usebox0%1\\end{minipage}") return text end \end{luacode*} \newcommand\CaptionAutoWidthOn{\directlua{luatexbase.add_to_callback ( "process_input_buffer" , caption_width , "caption_width" )}} \newcommand\CaptionAutoWidthOff{\directlua{luatexbase.remove_from_callback ( "process_input_buffer" , "caption_width" )}} #+end_src \CaptionAutoWidthOn #+CAPTION: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus #+ATTR_LaTeX: :width .3\linewidth [[img.jpg]] \CaptionAutoWidthOff #+CAPTION: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus #+ATTR_LaTeX: :width .1\linewidth [[img.jpg]]