MaTeX:在Mathematica的图片中插入LaTeX代码的工具

2024-02-04 00:48

本文主要是介绍MaTeX:在Mathematica的图片中插入LaTeX代码的工具,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Mathematica图片中对laTeX的支持实在不敢恭维。连Geogebra都比Mathematica强。


今天搜了一下,发现有这个工具可以用,看上去不错。

作者说32位的Windows下可能无法使用,所以,如果是win32就暂时不用尝试了;不过,我尝试了下,还是搞定了大笑

配置的时候,需要用这样的代码,而不是作者所提到的,不论32位还是64位windows都必须这样,很奇怪。仅供参考。


我把涉及到的GhostScript 920的windows版安装程序(32bit ,64bit)以及MaTeX源文件1.1.0版放在CSDN供下载。

ConfigureMaTeX[ "pdfLaTeX" ->  "X:\\Program Files\\CTEX\\MiKTeX\\miktex\\bin\\pdflatex.exe", "Ghostscript" -> "X:\\Program Files\\gs\\gs9.18\\bin\\gswin32c.exe"]


下载的github地址:https://github.com/szhorvat/MaTeX/releases

https://github.com/szhorvat/MaTeX/releases


https://github.com/szhorvat/MaTeX/archive/v1.6.3.zip

当前1.60

https://github.com/szhorvat/MaTeX/releases/download/v1.6.0/MaTeX-1.6.0.zip


建议使用1.3.0以前的版本;之后的版本作者把它们改得使用起来颇为繁琐。本来只是为了实现一个小小的功能,偏要添加太多复杂的花头。简单实用才好。

当前1.3.0版本

当前1.2.0版本

当前1.1.0版本

主页和介绍

http://szhorvat.net/pelican/latex-typesetting-in-mathematica.html

LaTeX typesetting in Mathematica

Thu 05 March 2015 By szhorvat

In Notes.

tags: mathematica

Mathematica is an excellent and flexible visualization tool, and even supports displaying complex mathematical formulae. However, its typesetting quality is not on par with LaTeX. The visual style is not a good match for inclusion in LaTeX documents either. To improve the quality of my figures, I wrote a small Mathematica package that makes it easy to use LaTeX-generated labels: MaTeX.

Update: The post below has been updated for MaTeX version 1.1.0. The changelog is available on GitHub.

There are already several solutions for this problem, such as PSTricks or drawing axes and labels withPGFPlots. None of these solutions make it easy to use a Mathematica-centric workflow though. MaTeX makes generating LaTeX-typeset expressions as simple as

I originally wrote these functions for my own needs, but seeing that others may be interested in them too, I wrapped them up into a package. Feel free to leave comments below and keep in mind that this it is still a work in progress.

Installation

To install MaTeX, download the latest release and drop the MaTeX.m file in the directory opened bySystemOpen@FileNameJoin[{$UserBaseDirectory, "Applications"}].

You will also need:

  • A TeX system that includes pdflatex with the standalone and lmodern packages. Both TeX Live and MiKTeX should work.
  • Ghostscript 9.15 or later.(Ghostscript 9.20)

    On OS X, MacTeX 2015 includes a compatible version of Ghostscript. If you use an older TeX distribution on OS X, get a recent Ghostscript from Richard Koch’s page.

When loading MaTeX for the first time, it will try to automatically detect TeX and Ghostscript. If this fails, it will display instructions on configuring the location of the pdflatex and gs executables using theConfigureMaTeX command. As an example, on my OS X system I needed to use the following configuration:

ConfigureMaTeX["pdfLaTeX" -> "/Library/TeX/texbin/pdflatex", "Ghostscript" -> "/usr/local/bin/gs"]

The existing configuration can always be queried using the command ConfigureMaTeX[].

Note: On Windows use the c-suffixed command line Ghostscript executable, i.e. gswin64c.exe instead ofgswin64.exe.

If you prefer, you can use xelatex instead of pdflatex. Unlike plain pdfLaTeX, XeLaTeX can load any installed system font.

MaTeX should now be ready to use. Test it using MaTeX["x^2"].

Usage examples

First we need to load MaTeX:

<<MaTeX`

My primary use for it is creating figure annotations, as below:

texStyle = {FontFamily -> "Latin Modern Roman", FontSize -> 12};
ContourPlot[x^2 + y^4 == 1, {x, -1.2, 1.2}, {y, -1.2, 1.2},BaseStyle -> texStyle,Epilog -> {Arrow[{{0.1, 0.3}, {0.5, 0.80}}],Inset[MaTeX["x^2+y^4=1", Magnification -> 2], {0.1, 0.3}, Scaled[{0.5, 1}]]}]

Here I used the Latin Modern font for tick labels for visual consistency with the MaTeX/LaTeX output.

We can also use MaTeX to generate beautifully typeset frame labels and frame ticks. Mathematica’s default frame and axes style is dark grey, while MateX outputs black. The BlackFrame style below makes the frames black too for consistency.

Plot[Sin[x], {x, 0, 2 Pi},Frame -> True, FrameStyle -> BlackFrame,FrameTicks -> {{Automatic, None},{Table[{x, MaTeX[x, "DisplayStyle" -> False]}, {x, Pi/4 Range[0, 8]}], None}},FrameLabel -> MaTeX /@ {"x", "\\sin x"},BaseStyle -> texStyle]

The MaTeX function can be used either with a string containing math-mode LaTeX code, or with an arbitrary Mathematica expression. It will automatically apply TeXForm to non-string expressions.

When writing TeX code in Mathematica strings, remember to always escape backslashes. Thus \sum must be written as "\\sum".

Advanced usage

Options

  • "DisplayStyle".  By default display style is used. Use "DisplayStyle" -> False for inline style.

    Inline formatting looks like  k=11k2=π26 ∑k=1∞1k2=π26. Display style looks like  k=11k2=π26 ∑k=1∞1k2=π26.

  • FontSize.  Use it to set the font size. Note that LaTeX uses different glyph shapes for different font sizes to improve readability. Depending on the font used, only standard sizes may be available with this option. Use Magnification instead for proportional scaling.

  • "Preamble".  This is a list of lines to be included in the LaTeX preamble. The default is{"\\usepackage{lmodern,exscale}", "\\usepackage{amsmath,amssymb}"}. The AMS packages are included by default because they may be required for compiling the output of Mathematica’s TeXForm, while lmodernprovides vector fonts and flexible font sizing. On most systems "\\usepackage{lmodern,exscale}" can be omitted.

    This option is most convenient to set permanently for the session, for example:

    SetOptions[MaTeX, "Preamble" -> {"\\usepackage{amsmath,amssymb}", "\\usepackage{color,txfonts}"}]
    MaTeX["\\color{red}\\sqrt{x}"]
  • Magnification.  Set a scaling factor for MaTeX’s output. Magnification scales the result proportionally, unlike FontSize, which will use different glyph shapes for small text.

Performance

MaTeX needs to call pdflatex for every  LATEX LATEX expression it generates. Each call might take as long as a second, which can be annoyingly slow when using MaTeX on many small expression, e.g. creating tick labels. As a partial remedy for this, MaTeX caches each result, so a second call with the same TeX code should be instantaneous.

The maximum number of expressions to be cached can be controlled using ConfigureMaTeX["CacheSize" -> ...].ClearMaTeXCache[] will clear the cache.

How does it work?

MaTeX uses pdflatex and the standalone document class to create PDF files from TeX code. The height of thePDF files is ensured to be at least the line height by including a \strut. Mathematica can import PDF files, but it can only interpret simple ones correctly. To avoid problems, all font glyphs are converted to outline curves using Ghostscript before import. This capability is new in Ghostscript 9.15, hence the version requirement.

Troubleshooting

MaTeX no longer works on OS X 10.11 El Capitan

If you use MacTeX on OS X El Capitan, the path to pdflatex or xelatex must be set as

ConfigureMaTeX["pdfLaTeX" -> "/Library/TeX/texbin/pdflatex"]

If you used the path /usr/texbin/pdflatex on OS X 10.10 or earlier, it will no longer work on 10.11. You must reconfigure MaTeX with the new path. Please see the explanation here.

The path to Ghostscript is unchanged, /usr/local/bin/gs.

Invalid syntax in or before <!DOCTYPE html>” error

This error indicates that MaTeX was not downloaded correctly. Please download the latest release of MaTeX.mfrom this page, and re-install it according to the instructions above.

MaTeX::texerr on 32-bit Windows

If you are using a 32-bit version of Mathematica on Windows, MaTeX may not work correctly and may show the following error every time the MaTeX function is used:

MaTeX::texerr: Error while running LaTeX

This is due to a bug in Mathematica for 32-bit Windows. Due to the rarity of this platform, I decided not to work around this problem. Please consider using the 64-bit version. If you must use the 32-bit version for some reason, contact me for partial workarounds.

MaTeX still doesn’t work!

Please restart Mathematica, then enter the following lines in a new notebook and evaluate them:

Needs["MaTeX`"]
ConfigureMaTeX[]
MaTeX`Developer`$Version

Save the notebook and email it to me along with a complete description of the problems you are seeing.

Comments !



这篇关于MaTeX:在Mathematica的图片中插入LaTeX代码的工具的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/675917

相关文章

揭秘未来艺术:AI绘画工具全面介绍

📑前言 随着科技的飞速发展,人工智能(AI)已经逐渐渗透到我们生活的方方面面。在艺术创作领域,AI技术同样展现出了其独特的魅力。今天,我们就来一起探索这个神秘而引人入胜的领域,深入了解AI绘画工具的奥秘及其为艺术创作带来的革命性变革。 一、AI绘画工具的崛起 1.1 颠覆传统绘画模式 在过去,绘画是艺术家们通过手中的画笔,蘸取颜料,在画布上自由挥洒的创造性过程。然而,随着AI绘画工

墨刀原型工具-小白入门篇

墨刀原型工具-小白入门篇 简介 随着互联网的发展和用户体验的重要性越来越受到重视,原型设计逐渐成为了产品设计中的重要环节。墨刀作为一款原型设计工具,以其简洁、易用的特点,受到了很多设计师的喜爱。本文将介绍墨刀原型工具的基本使用方法,以帮助小白快速上手。 第一章:认识墨刀原型工具 1.1 什么是墨刀原型工具 墨刀是一款基于Web的原型设计工具,可以帮助设计师快速创建交互原型,并且可以与团队

大学湖北中医药大学法医学试题及答案,分享几个实用搜题和学习工具 #微信#学习方法#职场发展

今天分享拥有拍照搜题、文字搜题、语音搜题、多重搜题等搜题模式,可以快速查找问题解析,加深对题目答案的理解。 1.快练题 这是一个网站 找题的网站海量题库,在线搜题,快速刷题~为您提供百万优质题库,直接搜索题库名称,支持多种刷题模式:顺序练习、语音听题、本地搜题、顺序阅读、模拟考试、组卷考试、赶快下载吧! 2.彩虹搜题 这是个老公众号了 支持手写输入,截图搜题,详细步骤,解题必备

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

JAVA读取MongoDB中的二进制图片并显示在页面上

1:Jsp页面: <td><img src="${ctx}/mongoImg/show"></td> 2:xml配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001

公共筛选组件(二次封装antd)支持代码提示

如果项目是基于antd组件库为基础搭建,可使用此公共筛选组件 使用到的库 npm i antdnpm i lodash-esnpm i @types/lodash-es -D /components/CommonSearch index.tsx import React from 'react';import { Button, Card, Form } from 'antd'

17.用300行代码手写初体验Spring V1.0版本

1.1.课程目标 1、了解看源码最有效的方式,先猜测后验证,不要一开始就去调试代码。 2、浓缩就是精华,用 300行最简洁的代码 提炼Spring的基本设计思想。 3、掌握Spring框架的基本脉络。 1.2.内容定位 1、 具有1年以上的SpringMVC使用经验。 2、 希望深入了解Spring源码的人群,对 Spring有一个整体的宏观感受。 3、 全程手写实现SpringM

Windows/macOS/Linux 安装 Redis 和 Redis Desktop Manager 可视化工具

本文所有安装都在macOS High Sierra 10.13.4进行,Windows安装相对容易些,Linux安装与macOS类似,文中会做区分讲解 1. Redis安装 1.下载Redis https://redis.io/download 把下载的源码更名为redis-4.0.9-source,我喜欢跟maven、Tomcat放在一起,就放到/Users/zhan/Documents

代码随想录算法训练营:12/60

非科班学习算法day12 | LeetCode150:逆波兰表达式 ,Leetcode239: 滑动窗口最大值  目录 介绍 一、基础概念补充: 1.c++字符串转为数字 1. std::stoi, std::stol, std::stoll, std::stoul, std::stoull(最常用) 2. std::stringstream 3. std::atoi, std

记录AS混淆代码模板

开启混淆得先在build.gradle文件中把 minifyEnabled false改成true,以及shrinkResources true//去除无用的resource文件 这些是写在proguard-rules.pro文件内的 指定代码的压缩级别 -optimizationpasses 5 包明不混合大小写 -dontusemixedcaseclassnames 不去忽略非公共