Plot2LaTeX

버전 2.3.1 (27.8 KB) 작성자: Christopher Schulte
Fork of Plot2LaTex.m by Jan de Jong
다운로드 수: 143
업데이트 날짜: 2024/2/28

Plot2LaTeX

Fork of Plot2LaTex.m by Jan de Jong. This fork adds the following features:

  • Support for newer versions of Matlab
  • Support for Inkscape v1.*
  • Support for multiple line text
  • Support for legend box resizing
  • Support for colored text
  • Additional options like removal of white background

Original files: https://www.mathworks.com/matlabcentral/fileexchange/52700-plot2latex

Creator: Jan de Jong https://www.mathworks.com/matlabcentral/profile/authors/4045895

Tested with Matlab 2016b-2020b on Microsoft Windows and Inkscape v1.*.

View Plot2LaTeX on File Exchange

Overview

PLOT2LATEX saves matlab figure as a PDF file in vector format for inclusion into LaTeX. Requires free and open-source vector graphics editor Inkscape. This allows links of varible names to be placed within the axis or legend and so on, or variables can be subsequently renamed without having to recreate the Matlab plot.

Options

PLOT2LATEX(h, filename, 'option1', value, 'option2', value, ...) or PLOT2LATEX(h, filename, options_struct) saves figure with specified options as name value pairs or with an options-struct with a subset of the following fieldnames:

Option Value Discription
'Renderer' 'painters' (default), 'opengl', '' (no change) Renderer of the figure. Only change if you know what you are doing.
'yCorrFactor' 0.8 (default, in px) Offset of all text in y-direction.
'legCorrFactor' 1.02 (default, in percent) Option for manually correct the horizontal size of a (vertical) legend.
'DIR_INKSCAPE' 'inkscape' (default), 'C:\Program Files\Inkscape\Inkscape.exe', ... Path to inkscape.exe
'Verbose' 'console' (default), 'waitbar', 'both' Should a waitbar appear to show progress or a console text
'useOrigFigure' false (default) Use the original figure or create a copy?
'OnlySVG' false (default) Option to stop after creating the SVG file. Can be used, if the plots are used as SVG files with the package SVG in LaTeX or if inkscape is not installed.
'Interpreter' '' (default), 'latex', 'none', tex' Changes the matlab text interpreter, if empty no change is made.
'FontSize' 'auto' (default), ' ' (do nothing), 'fixed', 14 (in pt) Should be equal to the font size inside the document, use '' if the font size should not be changed beforehand.
'ReplaceList' '' (default), a cell with 2 columns first column: text in figure, second column: new text in .svg: Should a placeholder text in the figure be replaced with a LaTeX command that e.g. matlab can't correctly display? Example : {'placeholder','\acr{thickness}'; 'placeholder2','$\exp{-4r^2}$'}
'Inkscape_Export_Mode' 'export-area-page' (default), 'export-area-drawing' inkscape export options, see wiki.inkscape.org
'RemoveWhiteBackground' true (default) Should the white background of the figure be removed from the SVG file?

Example function calls

  • PLOT2LATEX(gcf, 'FirstPlot')
  • PLOT2LATEX(gcf, 'FirstPlot', 'Verbose', false)
  • PLOT2LATEX(gcf, 'FirstPlot', 'doExportPDF', false, 'FontSize', '')

Info

Plot2LaTeX(h, filename) saves figure with handle h to a file specified by filename, without extention. Filename can contain a full path or a name (e.g. 'C:\images\title', 'title') to save the figure to a different location other than the current folder.

PLOT2LATEX requires an installation of Inkscape. The program's location can be 'hard coded' into this matlab file if 'inkscape' is not a valid command for the command window. Please specify your inscape file location by modifying opts.DIR_INKSCAPE variable on the first line of the actual code or specify the location of inkscape.exe on the first run.

PLOT2LATEX saves the figures to SVG format. It invokes Inkscape to save the SVG to a PDF and PDF_TEX file to be incorporated into LaTeX document using \begin{figure} \input{image.pdf_tex} \end{figure}. More information on the SVG to PDF conversion can be found here: ftp://ftp.fu-berlin.de/tex/CTAN/info/svg-inkscape/InkscapePDFLaTeX.pdf

PLOT2LATEX produces three files: SVG, PDF and PDF_TEX. The SVG-file contains thw vector image. The PDF-file contains the figure without the text. The PDF_TEX-file contains the text including locations and other type setting.

The produced SVG file can be manually modified in Inkscape and included into the .tex file using the built-in 'save to PDF' functionality of Inkscape.

PLOT2LATEX saves the figure to a SVG and PDF file with approximately the same width and height. Specify the Font size and size within Matlab for correct conversion.

Workflow of the code

  1. Matlab renames duplicate strings of the figure. The strings are stored to be used later. To prevent a change in texbox size, duplicate labels get '.' at the end of the label.
  2. Matlab saves the Figure with modified labels to a SVG file.
  3. Matlab opens the SVG file and restores the labels with the original string
  4. Matlab invokes Inkscape to save the SVG file to a PDF + PDF_TEX file.
  5. The pdf_tex is to be included into LaTeX. Instruction can be found inside the PDF_TEX file.

Features

  • Complex figures such as plotyy, logarithmic scales.
  • It parses LaTeX code, even if it is not supported by Matlab LaTeX.
  • support real transparency.
  • SVG is a better supported, maintained and editable format than eps
  • SVG allows simple manual modification into Inkscape.
  • PLOT2LATEX sets all text to the same size, based on the median of all text sizes present with option 'fontSize'='auto'. Use 'FontSize'='fixed' for variing text sizes in LaTeX.

Limitations

  • Text resize is still done in PLOT2LATEX. The LaTeX fonts in matlab do not correspond completely with the LaTeX font size.
  • Legend size is not always correct, use placeholder text elements that will be replaced based on the replaceList-option. Works with latex-functions that can't be compiled by matlab.
  • Text boxes with LaTeX code which is not interpretable by matlab results in too long text boxes. Use the replaceList-option.
  • Very large figures sometimes result in very large waiting times.
  • Older versions than matlab 2014b are not supported.

Troubleshooting

  • For Unix users: use the installation folder such as: '/Applications/Inkscape.app/Contents/Resources/script' as location.
  • For Unix users: For some users the bash profiles do not allow to call Inkscape in Matlab via bash. Therefore, change the bash profile in Matlab to something similar as setenv('DYLD_LIBRARY_PATH','/usr/local/bin/'). The bash profile location can be found by using '/usr/bin/env bash'

To do

  • Allow multiple line text
  • Speed up code by smarter string replacement of SVG file
  • Resize of legend box using: [h,icons,plots,str] = legend(); (not so simple)
  • Size difference .svg and .fig if specifying units other than px. (Matlab limitation?)

인용 양식

Christopher Schulte (2024). Plot2LaTeX (https://github.com/Don-Chris/Plot2LaTeX/releases/tag/2.3.1), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2016b
R2016b 이상 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

GitHub 디폴트 브랜치를 사용하는 버전은 다운로드할 수 없음

버전 게시됨 릴리스 정보
2.3.1

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/2.3.1

2.3

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/2.3

2.2.0.0

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/2.2

2.1

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/2.1

2.0

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/2.0

1.10

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/1.10

1.9

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/1.9

1.8

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/1.8

1.7.006

v 1.8 - 22/09/2022
- changed 'doExportPDF' to 'OnlySVG'
- added an option for Inkscape Export Mode

1.7.005

v 1.7 - 13/09/2022

fixed a bug in colorbar
legend size is fixed based on initial position
added an option for fontSize

1.7.004

v 1.7 - 13/09/2022

fixed a bug in colorbar
legend size is fixed based on initial position
added an option for fontSize

1.7.003

v 1.7 - 13/09/2022

fixed a bug in colorbar
legend size is fixed based on initial position
added an option for fontSize

1.7.002

v 1.7 - 13/09/2022

fixed a bug in colorbar
legend size is fixed based on initial position
added an option for fontSize

1.7.001

v 1.7 - 13/09/2022
- fixed a bug in colorbar
- legend size is fixed based on initial position
- added an option for fontSize

1.7

v 1.7 - 13/09/2022
- fixed a bug in colorbar
- legend size is fixed based on initial position
- added an option for fontSize

1.6

1.5.0.0

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/1.5

1.3.0.0

See release notes for this release on GitHub: https://github.com/Don-Chris/Plot2LaTeX/releases/tag/1.3

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.