Generate latex formulas in Emacs

Source: Internet
Author: User

There is a latexit software under the apple system, which can easily generate latex formulas and drag them to other programs for direct use. In Windows, there are fewer tools. However, if the ctex Chinese set and Emacs are installed, you may wish to build a simple version by yourself.

The idea is simple: open an Emacs buffer, edit the formula, and execute the self-developedTexifyFunction call related commands to generate the DVI file. Then, according to the method described in this article, we can crop it appropriately and generate multiple image formats at a time for other programs to use. This function is as follows:

(defun texify ()  (interactive)  (let* ((file-name)         (base-name))    (setq file-name (buffer-name))    (setq base-name (substring file-name 0 (string-match "\.tex" file-name)))    (message "Generate dvi...")    (if (equal (call-process "latex" nil (concat "*" file-name "*") t file-name) 0)        (progn          (message "Generate eps...")          (if (equal (call-process "dvips" nil (concat "*" file-name "*") t "-E" (concat base-name ".dvi") "-o" (concat base-name ".eps")) 0)              (progn                (message "Generate png...")                (if (equal (call-process "gswin32c" nil (concat "*" file-name "*") t "-dNOSAFER" "-r600" "-dBATCH" "-sDEVICE=pngalpha" "-dNOPAUSE" "-dEPSCrop" (concat "-sOutputFile=" base-name ".png") (concat base-name ".eps")) 0)                    (progn                      (message "Process png complete!")))))          (message "Generate pdf from eps...")          ;; -dEPSCrop is only effective for eps->pdf, not ps->pdf           (if (equal (call-process "gswin32c" nil (concat "*" file-name "*") t "-dNOSAFER" "-dBATCH" "-sDEVICE=pdfwrite" "-dNOPAUSE" "-dPDFSETTINGS=/printer" "-dCOMPatibilityLevel=1.4" "-dEPSCrop" "-dMaxSubsetPct=100" "-dSubsetFonts=true" "-dEmbedAllFonts=true" (concat "-sOutputFile=" base-name ".pdf") (concat base-name ".eps")) 0)              (progn                (message "Generate svg...")                ;; -ssp is used to remove black hole in some symbols such as a, e, etc.                 (if (equal (call-process "pstoedit" nil (concat "*" file-name "*") t "-f" "plot-svg" "-ssp" "-usebbfrominput" (concat base-name ".pdf") (concat base-name ".svg")) 0)                    (progn                      (message "Process svg complete!")))))))))

 

 

ByTexifyFunction-generated image formats include:

  • EPS: generated using the dvips command, which can be directly used in latex documents;

  • Background transparent PNG: generate with the gswin32ccommand. If the ctex is installed, the program has been installed. You only need to add the path where gswin32c.exe is located to the PATH environment variable. If the system is Linux, install ghostscript. The resolution of the generated PNG image is set to 600, which is used for MS Word and PPT display.

  • SVG: generate a PDF file from the EPS, and then convert the file from pstoedit to the SVG format. This file can be directly inserted into inkscape for vector graph creation or poster design. The pstoedit Command needs to be downloaded here.

To facilitate the input of mathematical formulas, you can prepare a template in advance and fill in the blanks each time. For example:

\documentclass{article}\newcommand{\myfont}{\fontsize{12pt}{18pt}\selectfont}\usepackage{amssymb,amsmath,amscd}\usepackage[amssymb]{SIunits}\usepackage{color}\usepackage{CJK}\newcommand{\bi}[1]{\boldsymbol{#1}}\newcommand{\abs}[1]{\vert #1 \vert}\newcommand{\diff}{{\rm d}}\newcommand{\intd}{\,{\rm d}}\newcommand{\vect}[1]{\boldsymbol{#1}}\begin{document}\pagestyle{empty}\begin{CJK*}{GBK}{song}\myfont%% latex goes here %% latex ends here\clearpage\end{CJK*}\end{document}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.