4

I want to create a style file for the tcolorbox environment. I have the following:

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (LaTeX-add-environments
         '("tcolorbox")
         ))
      )

However, I want Emacs to query for the optional [title=] parameter. How can I do that?

3

You should use the LaTeX-env-args function (see the documentation for more information). In your case:

(LaTeX-add-environments
   '("tcolorbox" LaTeX-env-args [TeX-arg-key-val (("title"))]))

There are some style files using this feature, you should check them out.

If you're writing a style file for the tcolorbox package, I strongly suggest you to submit it to the AUCTeX mailing list so it can be added upstream.

  • Well, I'm queried, but the result is simply [text I typed]. I'll check the documentation you pointed at. Thanks. – NVaughan Feb 4 '15 at 1:11
1

Using @giordano's suggestion, and examining other styles, I managed to do this:

(defun LaTeX-tcolorbox-env-item-opt-label (environment)
  "Insert a `tcolorbox` environment with an optional title."
  (LaTeX-insert-environment
   environment
   (let ((label (TeX-read-string "(Optional) Title: ")))
     (concat (unless (zerop (length label))
               (format "[title={%s}]" label))))))

(add-hook 'LaTeX-mode-hook
          (lambda ()
            (LaTeX-add-environments
             '("tcolorbox" LaTeX-tcolorbox-env-item-opt-label))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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