From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- graphics/AddTeX2Eps/AddTeX2Eps-Example.nb | 108 +++++++++++++++++++ graphics/AddTeX2Eps/AddTeX2Eps.m | 172 ++++++++++++++++++++++++++++++ graphics/AddTeX2Eps/README | 1 + graphics/AddTeX2Eps/default.tex | 49 +++++++++ graphics/AddTeX2Eps/readme.txt | 26 +++++ 5 files changed, 356 insertions(+) create mode 100644 graphics/AddTeX2Eps/AddTeX2Eps-Example.nb create mode 100644 graphics/AddTeX2Eps/AddTeX2Eps.m create mode 120000 graphics/AddTeX2Eps/README create mode 100644 graphics/AddTeX2Eps/default.tex create mode 100644 graphics/AddTeX2Eps/readme.txt (limited to 'graphics/AddTeX2Eps') diff --git a/graphics/AddTeX2Eps/AddTeX2Eps-Example.nb b/graphics/AddTeX2Eps/AddTeX2Eps-Example.nb new file mode 100644 index 0000000000..8b3ee8b2cb --- /dev/null +++ b/graphics/AddTeX2Eps/AddTeX2Eps-Example.nb @@ -0,0 +1,108 @@ +(* Content-type: application/mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 7.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 145, 7] +NotebookDataLength[ 3095, 99] +NotebookOptionsPosition[ 2626, 79] +NotebookOutlinePosition[ 2967, 94] +CellTagsIndexPosition[ 2924, 91] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ +Cell["\<\ +Copy the package AddTeX2Eps.m and the default.tex into the folder: \ +\\AddOns\\Packages\\EpsTools\\\ +\>", "Text", + CellChangeTimes->{{3.5608370086083517`*^9, 3.5608370519718323`*^9}, { + 3.5608378516945734`*^9, 3.560837858357955*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Needs", "[", "\"\\"", "]"}], ";"}]], "Input", + CellChangeTimes->{{3.465217586163*^9, 3.465217588227*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{"fig", "=", + RowBox[{"Plot", "[", + RowBox[{ + RowBox[{"Sin", "[", + RowBox[{"x", "^", "2"}], "]"}], ",", + RowBox[{"{", + RowBox[{"x", ",", "0", ",", "4"}], "}"}], ",", + RowBox[{"AxesLabel", "\[Rule]", + RowBox[{"{", + RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", + RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]}], ";"}], "\n", + RowBox[{"EpsExport", "[", + RowBox[{"\"\\"", ",", "fig", ",", + RowBox[{"{", + RowBox[{ + "\"\<\\\\psfrag{a}[c]{$x$}\>\"", ",", + "\"\<\\\\psfrag{b}[c]{$\\\\sin(x^2)$}\>\"", ",", + "\"\<\\\\psfrag{c}[c]{Native \\\\LaTeX via psfrag package}\>\""}], + "}"}]}], "]"}]}], "Input", + CellChangeTimes->{{3.4652175797939997`*^9, 3.4652175803450003`*^9}, + 3.465217610743*^9}], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{"Options", "[", "EpsExport", "]"}], "\n", + RowBox[{"CorrectBB", "::", "usage"}]}], "Input", + CellChangeTimes->{3.465217614446*^9}], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"CorrectBB", "\[Rule]", + RowBox[{"{", + RowBox[{"0", ",", "0", ",", "0", ",", "0"}], "}"}]}], ",", + RowBox[{"IncludeGraphicsOptions", "\[Rule]", "\<\"[scale=1.0]\"\>"}], ",", + RowBox[{"DeleteTempFiles", "\[Rule]", "True"}]}], "}"}]], "Output", + CellChangeTimes->{3.46521761496*^9, 3.465217768177*^9}], + +Cell[BoxData["\<\"Use to manually correct bounding box dimensions: {llx, lly, \ +urx, ury}.\\n\\nFor example: {-10, 0, 0, 0} moves the lower left bounding box \ +point for 10 points to the left.\"\>"], "Output", + CellChangeTimes->{3.46521761496*^9, 3.4652177681800003`*^9}] +}, Open ]] +}, +WindowSize->{495, 589}, +WindowMargins->{{0, Automatic}, {Automatic, 0}}, +FrontEndVersion->"8.0 for Microsoft Windows (64-bit) (October 6, 2011)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[545, 20, 244, 5, 47, "Text"], +Cell[792, 27, 163, 3, 31, "Input"], +Cell[958, 32, 830, 22, 152, "Input"], +Cell[CellGroupData[{ +Cell[1813, 58, 155, 3, 52, "Input"], +Cell[1971, 63, 365, 8, 69, "Output"], +Cell[2339, 73, 271, 3, 107, "Output"] +}, Open ]] +} +] +*) + +(* End of internal cache information *) diff --git a/graphics/AddTeX2Eps/AddTeX2Eps.m b/graphics/AddTeX2Eps/AddTeX2Eps.m new file mode 100644 index 0000000000..34afe29114 --- /dev/null +++ b/graphics/AddTeX2Eps/AddTeX2Eps.m @@ -0,0 +1,172 @@ +(* ::Package:: *) + +(* :Title: AddTeX2Eps *) +(* :Context: EpsTools`AddTeX2Eps` *) +(* :Author: Janko Slavic (janko.slavic@fs.uni-lj.si) *) +(* :Summary: + Package for using native LaTeX syntax on eps figures directly from Mathematica. + AddTeX2Eps calls latex.exe and dvips.exe and makes use of psfrag package (needs to be installed). + + default.tex is the LaTeX template where you can add packages and define your own LaTeX commands. + Copy default.tex and AddTeX2Eps.m to ..\AddOns\StandardPackages\Graphics\ or to search path. + +*) +(* :Package Version: 1.14 *) +(* :Mathematica Version: 7.0 *) +(* :History: + 1.14 by Janko Slavic, October, 2009 (some fixes for Mathematica 7.0). + 1.13 by Janko Slavic, December, 2006 (for linux compatibility default.tex is always used as lowercase). + 1.12 by Janko Slavic, April, 2006 (default.tex located in searh path or ..\AddOns\StandardPackages\Graphics\). + 1.11 by Janko Slavic, April, 2006 (directory problem resolved). + 1.1 by Janko Slavic, April, 2006. + 1.0 by Janko Slavic, 2003. +*) +(* :Keywords: eps, tex, latex, psfrag. +*) + + +BeginPackage["EpsTools`AddTeX2Eps`"] + +EpsExport::usage="EpsExport[fileName,graphics,PSFrag] +EpsExport is used to export graphics to eps files +and then use psfrag LaTeX package with latex.exe and dvips.exe. \n +fileName is a string with full path (long names and spaces can cause troubles)\n +graphics is a graphical object to export\n +PSFrag is List of strings with psfrag syntax\n +\n +Example:\n\n +Needs[\"EpsTools`AddTeX2Eps`\"];\n +fig = Plot[Sin[x^2], {x, 0, 4}, AxesLabel -> {\"a\",\"b\"},PlotLabel -> \"c\"];\n +EpsExport[\"d:/test.eps\",fig,\n +{\n +\"\\psfrag{a}[c]{$x$}\",\n +\"\\psfrag{b}[c]{$\\sin(x^2)$}\",\n +\"\\psfrag{c}[c]{Native \\LaTeX via psfrag package}\"\n +}] +"; + +CorrectBB::usage="Use to manually correct bounding box dimensions: {llx, lly, urx, ury}.\n +For example: {-10, 0, 0, 0} moves the lower left bounding box point for 10 points to the left."; + +IncludeGraphicsOptions ::usage="Native LaTeX includegraphics options (scale, trim,...)"; + +DeleteTempFiles::usage="If you are having problems with compiling, it may help to look at the temporary files. + Try to compile temp.tex with latex.exe." + +Options[EpsExport]={ + CorrectBB -> {0, 0, 0, 0}, + IncludeGraphicsOptions -> "[scale=1.0]", + DeleteTempFiles -> True}; + +Begin["`Private`"] + +EpsExport[fileName_String, graphics_, PSFrag_List, opts___] := + Module[{stream}, + Export[fileName, graphics, "EPS"]; + stream = OpenAppend[fileName]; + (*Save PSFrag syntax in file - if needed later*) + WriteString[stream, + "%%PSFragBegin\n" <> StringJoin[StringInsert[PSFrag,"\n%%",1]] <> + "\n%%PSFragEnd"]; + Close[stream]; + + (*run latex and ps*) + RunLaTeX[fileName, PSFrag, opts]; + ]; + + +RunLaTeX[fileName_String, PSFrag_List, opts___] := + Module[{texDat, bbText, bb, stream, w, h, workD, llx, lly, urx, ury, + epsFile, tmp, deleteTempFiles}, + {{cllx, clly, curx, cury}, incGrapOpts, + deleteTempFiles} = {CorrectBB, IncludeGraphicsOptions, + DeleteTempFiles} /. Flatten[{opts}] /. Options[EpsExport]; + + (*default.tex needs to be in Graphics dir*) + (*if needed, add packages/new commands to default.tex*) + texDat := Module[{out}, + out=Import["EpsTools//default.tex", "Text"]; + out + ]; + + (*Read bounding box*) + stream = OpenRead[fileName]; + bbText = Find[stream, "%%BoundingBox:"]; + bb = ToExpression[Drop[StringSplit[bbText], 1]]; + Close[stream]; + {w, h} = IntegerPart[{bb[[3]] - bb[[1]], bb[[4]] - bb[[2]]}]; + + + + (*Prepare TeX dat*) + texDat = StringReplace[texDat, + {"psfragSyntax" -> StringJoin[StringInsert[PSFrag,"\n",1]], + "[scaleSyntax]" -> incGrapOpts, + "figureName" -> StringReplace[StringReplace[fileName, "/" -> $PathnameSeparator], __ ~~$PathnameSeparator~~ name_ -> name], + "{width}" -> "{" <> ToString[w] <> "pt}", + "{height}" -> "{" <> ToString[h] <> "pt}" + }]; + + + (*set working dir*) + workDir = Directory[]; + SetDirectory[DirectoryName[StringReplace[fileName, "/" -> $PathnameSeparator]]]; + + (*Export tex*) + Export["EpsExport.tex", texDat, "Text"]; + + (*Run Latex*) + Run["latex EpsExport"]; + + (*Run dvi to ps*) + Run["dvips -E EpsExport"]; + + + (*read bounding box*) + stream = OpenRead["EpsExport.ps"]; + bbText = Find[stream, "%%BoundingBox:"]; + {llx, lly, urx, ury} = ToExpression[Drop[StringSplit[bbText], 1]]; + Close[stream]; + + + + + (*correct bounding box*) + {llx, ury, lly, urx} = {urx - w + cllx, lly + h + cury, lly + clly, + urx + curx}; + bbText = + ToString[llx] <> " " <> ToString[lly] <> " " <> ToString[urx] <> " " <> + ToString[ury]; + epsFile = Import["EpsExport.ps", "Lines"]; + epsFile = Join[ + + StringReplace[Take[epsFile, 20], + StartOfLine ~~ "%%BoundingBox:" ~~ tmp__ -> + "%%BoundingBox: " ~~ bbText], + Drop[epsFile, 20] + ]; + Export[fileName, epsFile, "Lines"]; + + (*covert to pdf*) + (*If[convertToPdf,Run["ps2pdf "<>fileName<>" "<>StringDrop[fileName,-4]<>".pdf"];];*) + + (*delete files*) + If[deleteTempFiles, + DeleteFile[{"EpsExport.ps", "EpsExport.aux", "EpsExport.dvi", "EpsExport.log", + "EpsExport.tex"}]; + ]; + + + + + (*reset working dir*) + SetDirectory[workDir]; + + ]; + + +End[] + +Protect[EpsExport] + +EndPackage[] diff --git a/graphics/AddTeX2Eps/README b/graphics/AddTeX2Eps/README new file mode 120000 index 0000000000..0d79d56d9f --- /dev/null +++ b/graphics/AddTeX2Eps/README @@ -0,0 +1 @@ +readme.txt \ No newline at end of file diff --git a/graphics/AddTeX2Eps/default.tex b/graphics/AddTeX2Eps/default.tex new file mode 100644 index 0000000000..3a2217554e --- /dev/null +++ b/graphics/AddTeX2Eps/default.tex @@ -0,0 +1,49 @@ +% Author: Janko Slavic (janko.slavic@fs.uni-lj.si) +% 2012, version 1.15 +% +% This file is used by AddTeX2Eps.m package +% +%%%%%%%%%%%%%%%% +% Add packages if you need! % +%%%%%%%%%%%%%%%% +\documentclass{article} +\usepackage[slovene]{babel} +\usepackage[cp1250]{inputenc} +\usepackage{psfrag} +\usepackage[dvips]{graphicx,color} +\setlength{\paperwidth}{width}% +\setlength{\paperheight}{height}% +\setlength{\hoffset}{-1in}% +\setlength{\voffset}{-1in}% +\setlength{\oddsidemargin}{0 pt}% +\setlength{\evensidemargin}{0 pt}% +\setlength{\headheight}{0 pt}% +\setlength{\headsep}{0 pt}% +\setlength{\topmargin}{0 pt}% +\setlength{\textwidth}{width}% +\setlength{\textheight}{height}% +\setlength{\marginparsep}{0 pt}% +\setlength{\marginparwidth}{0 pt}% +\setlength{\footskip}{0 pt}% +\setlength{\marginparpush}{0 pt}% + + +%%%add commands%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% differentiate +\newcommand{\dif} + { + \textrm{d} + } +% + + +%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%% +\pagestyle{empty} +\begin{document} +\begin{figure} + \centering % + psfragSyntax + \includegraphics[scaleSyntax]{figureName} +\end{figure} +\end{document} diff --git a/graphics/AddTeX2Eps/readme.txt b/graphics/AddTeX2Eps/readme.txt new file mode 100644 index 0000000000..549f60f532 --- /dev/null +++ b/graphics/AddTeX2Eps/readme.txt @@ -0,0 +1,26 @@ +% Janko Slavic (janko.slavic@fs.uni-lj.si) +% 2006, version 1.1 + + +%%%%%%%%% +% Installation: % +Be sure to have installed psfrag package: http://www.ctan.org/tex-archive/macros/latex/contrib/psfrag/ +(If using MikTeX go to MikTeX options/packages and install psfrag). + +default.tex is the LaTeX template where you can add packages and define your own LaTeX commands. +Copy default.tex and AddTeX2Eps.m to ..\AddOns\StandardPackages\Graphics\ or to search path. +%%%%%%%%% + + +%%%%%%%%%%%% +% Example of usage: % +Needs["Graphics`AddTeX2Eps`"]; +Options[EpsExport] +CorrectBB::usage +fig = Plot[Sin[x^2], {x, 0, 4}, AxesLabel -> {"a","b"},PlotLabel -> "c"]; +EpsExport["d:/test.eps",fig,{ + "\\psfrag{a}[c]{$x$}", + "\\psfrag{b}[c]{$\\sin(x^2)$}", + "\\psfrag{c}[c]{Native \\LaTeX via psfrag package}" + }] +%%%%%%%%%%%% \ No newline at end of file -- cgit v1.2.3