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 just want to write the B_25 in org file and export as \(B_{25}\) to LaTeX file 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?

  • Why wouldn't you just find and replace all subscript occurrences in your file once? Eg. M-x replace-regex \([[:alnum:]]+\)_\([[:alnum:]]+\) $\\textit{\1}_{\2}$. – wvxvw Nov 22 '15 at 9:29
  • This is still cumbersome. Because I always add new subscripts, I need to do the replace many times. – Leu_Grady Nov 22 '15 at 9:38
  • looking at org-element-subscript-parser, I'm not sure this is worth the hassle. You'd have to (temporarily) extend the org-match-substring-regexp to include the symbol before the subscript. – mutbuerger Nov 23 '15 at 5:55

Your Answer

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

Browse other questions tagged or ask your own question.