Giter Site home page Giter Site logo

study-notes's People

Watchers

 avatar

study-notes's Issues

org-mode中使用tikz绘图

原理

由于 divpng 不支持 tikz,因此我们需要借助 imagemagicktikz 生成的 pdf 文件转换为图片文件。

安装imagemagick

*nix系统可通过包管理软件安装:

brew install imagemagick

配置

修改 org-modelatex 的图片生成软件为 imagemagick ,这里以 doom emacs 为例:

(after! org
  :config
  (setq org-preview-latex-default-process 'imagemagick)
  (setq org-latex-packages-alist
          '(("" "newpxtext,newpxmath" t)
            ("" "tikz" t)
            ("" "tikz-cd" t)
            ("" "eulervm" t)))
  (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.6))
  (with-eval-after-load "preview"
      (add-to-list 'preview-default-preamble "\\PreviewEnvironment{tikzpicture}" t)))

使用

org 文件头添加以下配置 :

#+LATEX_HEADER: \usepackage{tikz} \usepackage{pgf -umlcd} \usepgflibrary{arrows} \usepackage{color}
#+PROPERTY: header-args:latex :headers '("\\usepackage{tikz}") :fit yes :imagemagick yes :iminoptions -density 300 :imoutoptions
#+OPTIONS: tex:imagemagick

完成以上步骤,便可以在 latex 代码块中调用 org-latex-preview 方法预览 tikz 绘制的图片了(快捷键 C-c C-x C-l )。

\begin{tikzpicture}
    \foreach \n in {0,...,8} {
      \pgfmathsetmacro{\x}{mod(\n,3)+.5}
      \pgfmathsetmacro{\y}{2.5-div(\n,3)}
      \pgfmathsetmacro{\m}{int(\n+1)}
      \pgfmathsetmacro{\c}{mod(\n,2) ? "red!40" : "gray!70"}
      \fill[\c] (\x-.5,\y-.5) rectangle (\x+.5,\y+.5);
      \node at (\x, \y) {\m};
    }
    \draw (0,0) grid (3,3);
  \end{tikzpicture}

参考

LaTeX Source Code Blocks in Org Mode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.