From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: How can I wrap the subscript into a math environment in Org-mode? Date: Sun, 22 Nov 2015 08:54:13 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0V5v-0001os-Vq for emacs-orgmode@gnu.org; Sun, 22 Nov 2015 08:54:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0V5s-0002pS-Os for emacs-orgmode@gnu.org; Sun, 22 Nov 2015 08:54:19 -0500 Received: from mail-qk0-x22b.google.com ([2607:f8b0:400d:c09::22b]:34773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0V5s-0002pH-Jy for emacs-orgmode@gnu.org; Sun, 22 Nov 2015 08:54:16 -0500 Received: by qkfo3 with SMTP id o3so50459780qkf.1 for ; Sun, 22 Nov 2015 05:54:16 -0800 (PST) In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Lei Zhe Cc: "emacs-orgmode@gnu.org" it sounds like you are looking for a way to conveniently entering equations in LaTeX to me. This is seems like a case where you cannot have it both ways, that is convenient subscripts in math and text that are easy to tell the difference between, e.g. in H_{2}O you do not want the letters in math mode, but in e^{x}=3 you do. It is hard to see how a filter function would always do the right thing here. The easiest thing is probably to make a function to make it simple to add equations, e.g. this function will wrap a selected region in $$ (or \(\) with a prefix arg) or insert those so you can type in the equation. I bind it to super-4 which is pretty easy to use. you could also try some kind of yasnippet approach. (defun latex-math-region-or-point (&optional arg) (interactive "P") (let ((chars (if arg '("\\(" . "\\)") '("$" . "$")))) (if (region-active-p) (progn (goto-char (region-end)) (insert (car chars)) (goto-char (region-beginning)) (insert (cdr chars))) (insert (concat (car chars) (cdr chars))) (backward-char (length (cdr chars)))))) (define-key global-map (kbd "s-4") 'latex-math-region-or-point) Lei Zhe writes: > I have some subscripts in my org file like B_25, B_30. These > subscripts can be exported to LaTeX like B_{25}, B_{30}. However, I > want part of the subscripts like B to be exported as italic /B/. As > one solution for this, I can wrap these thing into a math environment > like \(B_{25}\). But since my file contains large numbers of these > subscripts, I would like to implement this in a programmable way. > > I found a subscript filter function in org-mode, so I tried to use it > to wrap the subscripts by > > (defun wrap-subscript-with-math-environment (contents backend info) > (when (eq backend 'latex) > (format "\\(%s\\)" contents))) > > (add-to-list 'org-export-filter-subscript-functions > 'wrap-subscript-with-math-environment) > However, the results exported are like B\($_{\text{25}}$ \). It seems > like the subscript filter contents only contain _25 part. Does anyone > have some solutions about this? -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu