diff --git a/CellsToTeX/CellsToTeX.m b/CellsToTeX/CellsToTeX.m index 61b4cec..7549608 100644 --- a/CellsToTeX/CellsToTeX.m +++ b/CellsToTeX/CellsToTeX.m @@ -22,6 +22,13 @@ contains converted cell contents and data extracted from Cell options." +CellsToTeXPreamble::usage = +"\ +CellsToTeXPreamble[] \ +returns String with TeX code setting global properties of mmacells package, \ +suitable for inclusion in document preamble." + + CellsToTeXException::usage = "\ CellsToTeXException \ @@ -142,6 +149,20 @@ or of symbol with given \"name\"." +texMathReplacement::usage = +"\ +texMathReplacement[\"str\"] \ +returns String with TeX code representing given String \"str\". By default \ +DownValues of texMathReplacement are used by CellsToTeXPreamble." + + +texMathReplacementRegister::usage = +"\ +texMathReplacementRegister[\"str\"] \ +defines TeX code math replacement for given String \"str\", if it's not \ +already defined. Returns \"str\"." + + makeString::usage = "\ makeString[boxes] \ @@ -1456,11 +1477,15 @@ cell form (String or None)." (*optionValueToTeX*) +optionValueToTeX[True] = "true" + +optionValueToTeX[False] = "false" + +optionValueToTeX[subOpts:{OptionsPattern[]}] := optionsToTeX["{", subOpts, "}"] + optionValueToTeX[val_] := With[{str = ToString[val]}, - If[StringTake[str, 1] === "{" && StringTake[str, -1] === "}" || - StringFreeQ[str, {"[", "]", ",", "="}] - , + If[StringMatchQ[str, "{*}"] || StringFreeQ[str, {"[", "]", ",", "="}], str (* else *), "{" <> str <> "}" @@ -1472,13 +1497,14 @@ cell form (String or None)." (*optionsToTeX*) -optionsToTeX[keyval:{(Rule | RuleDelayed)[_String, _]...}] := - StringJoin[Riffle[(#1 <> "=" <> optionValueToTeX[#2]) & @@@ keyval, ","]] +optionsToTeX[keyval:{OptionsPattern[]}] := + StringJoin @ + Riffle[(ToString[#1] <> "=" <> optionValueToTeX[#2]) & @@@ keyval, ","] optionsToTeX[_String, {}, _String] := "" optionsToTeX[ - pre_String, keyval:{(Rule | RuleDelayed)[_String, _]...}, post_String + pre_String, keyval:{OptionsPattern[]}, post_String ] := pre <> optionsToTeX[keyval] <> post @@ -1917,6 +1943,22 @@ cell form (String or None)." defaultAnnotationType[_Symbol | _String] := "UndefinedSymbol" +(* ::Subsubsection:: *) +(*texMathReplacementRegister*) + + +texMathReplacementRegister[str_String] := ( + If[! StringQ @ texMathReplacement[str], + With[{texCode = StringTrim @ System`Convert`TeXFormDump`MakeTeX[str]}, + If[texCode =!= "", + texMathReplacement[str] = texCode + ] + ] + ]; + str +) + + (* ::Subsubsection:: *) (*charToTeX*) @@ -2478,8 +2520,11 @@ cell form (String or None)." (*Common operations*) -Protect @ Evaluate @ Names[ - "CellsToTeX`Configuration`" ~~ Except["$"] ~~ Except["`"]... +Protect @ Evaluate @ DeleteCases[ + Names["CellsToTeX`Configuration`" ~~ Except["$"] ~~ Except["`"] ...], + "texMathReplacement", + {1}, + 1 ] @@ -2560,6 +2605,106 @@ cell form (String or None)." ] +(* ::Subsubsection:: *) +(*CellsToTeXPreamble*) + + +Options[CellsToTeXPreamble] = { + "Gobble" -> Automatic, + "UseListings" -> Automatic, + "TeXOptions" -> {}, + "TeXMathReplacement" -> texMathReplacement, + "CatchExceptions" -> True +} + + +functionCall:CellsToTeXPreamble[OptionsPattern[]] := + If[OptionValue["CatchExceptions"], + catchException + (* else *), + Identity + ] @ Module[ + {gobble, useListings, texOptions, mathReplacement} + , + {gobble, useListings, texOptions, mathReplacement} = + OptionValue @ + {"Gobble", "UseListings", "TeXOptions", "TeXMathReplacement"}; + + If[!MatchQ[texOptions, {OptionsPattern[]}], + throwException[functionCall, + {"Unsupported", "OptionValue", "TeXOptions"}, + {texOptions, {"list of options"}} + ] + ]; + If[!MatchQ[mathReplacement, Except[HoldPattern@Symbol[___], _Symbol]], + throwException[functionCall, + {"Unsupported", "OptionValue", "TeXMathReplacement"}, + {mathReplacement, {"a symbol"}} + ] + ]; + + (* By default gobble default indentation of mmaCell. *) + If[gobble === Automatic, + gobble = + StringLength @ OptionValue[mmaCellProcessor, "Indentation"] + ]; + Switch[gobble, + _Integer?NonNegative, + PrependTo[texOptions, "morefv" -> {"gobble" -> gobble}] + , + Except[None], + throwException[functionCall, + {"Unsupported", "OptionValue", "Gobble"}, + {gobble, {Automatic, None, "non-negative integer"}} + ] + ]; + + (* Listings are used to highlight non-annotated code using TeX + environment options. If moving annotations to options is switched + off then, by default, don't use listings, otherwise use them. + Since listings are, by default, switched on in mmacells package, + if we're using them, we can just omit this option. *) + If[useListings === Automatic, + useListings = + Replace[ + OptionValue[ + annotateSyntaxProcessor, + "CommonestTypesAsTeXOptions" + ], + Except[False] -> None + ] + ]; + Switch[useListings, + True | False, + PrependTo[texOptions, "uselistings" -> useListings] + , + Except[None], + throwException[functionCall, + {"Unsupported", "OptionValue", "UseListings"}, + {useListings, {Automatic, True, False, None}} + ] + ]; + StringJoin @ Riffle[ + DeleteCases[ + Prepend[ + StringJoin[ + "\\mmaDefineMathReplacement{", + #1[[1, 1]], + "}{", + #2, + "}" + ]& @@@ + DownValues @ Evaluate[mathReplacement] + , + optionsToTeX["\\mmaSet{", texOptions, "}"] + ], + "" + ], + "\n" + ] + ] + + (* ::Subsubsection:: *) (*Common operations*) diff --git a/CellsToTeX/Tests/Integration/CellToTeX.mt b/CellsToTeX/Tests/Integration/CellToTeX.mt index f4eb285..35cc527 100644 --- a/CellsToTeX/Tests/Integration/CellToTeX.mt +++ b/CellsToTeX/Tests/Integration/CellToTeX.mt @@ -104,6 +104,47 @@ Block[{\[Phi]1}, ] +Block[{texMathReplacement}, + texMathReplacement["\[UnderBracket]"] = "\\textvisiblespace"; + UsingFrontEnd @ Test[ + CellToTeX[ + { + \[Alpha]_ \[RuleDelayed] \[Alpha], + x \[Equal] \[Beta]\[UnderBracket]\[Gamma] + } // MakeBoxes + , + "Style" -> "Code", + "ProcessorOptions" -> { + "NonASCIIHandler" -> texMathReplacementRegister, + "CharacterEncoding" -> "Unicode" + } + ] + , + "\ +\\begin{mmaCell}{Code} + {\\mmaPat{\[Alpha]_} :> \\mmaPat{\[Alpha]}, x == \\mmaUnd{\[Beta]\[UnderBracket]\[Gamma]}} +\\end{mmaCell}" + , + TestID -> "pure boxes: syntax, non-ASCII symbols (private Unicode): \ +Code, Unicode encoding, math replacements" + ]; + Test[ + texMathReplacement // DownValues + , + { + HoldPattern@texMathReplacement@"\[Alpha]" :> "\\alpha", + HoldPattern@texMathReplacement@"\[Beta]" :> "\\beta", + HoldPattern@texMathReplacement@"\[Gamma]" :> "\\gamma", + HoldPattern@texMathReplacement@"\[UnderBracket]" :> + "\\textvisiblespace" + } + , + TestID -> "pure boxes: syntax, non-ASCII symbols (private Unicode): \ +Code, Unicode encoding, math replacements: texMathReplacement" + ] +] + + Test[ CellToTeX[ BoxData @ RowBox[{ diff --git a/CellsToTeX/Tests/Integration/CellsToTeXPreamble.mt b/CellsToTeX/Tests/Integration/CellsToTeXPreamble.mt new file mode 100644 index 0000000..304a806 --- /dev/null +++ b/CellsToTeX/Tests/Integration/CellsToTeXPreamble.mt @@ -0,0 +1,324 @@ +(* Mathematica Test File *) + +(* ::Section:: *) +(*SetUp*) + + +BeginPackage["CellsToTeX`Tests`Integration`CellsToTeXPreamble`", {"MUnit`"}] + + +Get["CellsToTeX`"] + +$ContextPath = + Join[{"CellsToTeX`Configuration`", "CellsToTeX`Backports`"}, $ContextPath] + + +(* ::Section:: *) +(*Tests*) + + +(* ::Subsection:: *) +(*Default*) + + +Test[ + CellsToTeXPreamble[] + , + "\\mmaSet{morefv={gobble=2}}" + , + TestID -> "Default" +] +Internal`InheritedBlock[{texMathReplacement}, + texMathReplacement["\[Alpha]"] = "\\alpha"; + texMathReplacement["\[Beta]"] = "\\beta"; + + Test[ + CellsToTeXPreamble[] + , + "\ +\\mmaSet{morefv={gobble=2}} +\\mmaDefineMathReplacement{\[Alpha]}{\\alpha} +\\mmaDefineMathReplacement{\[Beta]}{\\beta}" + , + TestID -> "Default: defined texMathReplacement" + ] +] + + +(* ::Subsection:: *) +(*Gobble option*) + + +Internal`InheritedBlock[{mmaCellProcessor}, + SetOptions[mmaCellProcessor, "Indentation" -> "1234557"]; + + Test[ + CellsToTeXPreamble["Gobble" -> Automatic] + , + "\\mmaSet{morefv={gobble=7}}" + , + TestID -> "Gobble -> Automatic" + ] +] +Test[ + CellsToTeXPreamble["Gobble" -> 4] + , + "\\mmaSet{morefv={gobble=4}}" + , + TestID -> "Gobble -> 4" +] +Test[ + CellsToTeXPreamble["Gobble" -> None] + , + "" + , + TestID -> "Gobble -> None" +] +Module[{unsupportedValue}, + With[ + { + heldMessage = + HoldForm @ Message[CellsToTeXException::unsupported, + HoldForm @ + CellsToTeXPreamble["Gobble" -> unsupportedValue], + HoldForm @ CellsToTeXException[ + "Unsupported", "OptionValue", "Gobble" + ], + HoldForm @ "OptionValue", + HoldForm @ unsupportedValue, + HoldForm @ {Automatic, None, "non-negative integer"} + ] + } + , + TestMatch[ + CellsToTeXPreamble["Gobble" -> unsupportedValue] + , + Failure[ + CellsToTeXException["Unsupported", "OptionValue", "Gobble"], + Association[ + "MessageTemplate" :> CellsToTeXException::unsupported, + "MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]] + ] + ] + , + {heldMessage} + , + TestID -> "Gobble -> unsupportedValue" + ] + ] +] + + +(* ::Subsection:: *) +(*UseListings option*) + + +Internal`InheritedBlock[{annotateSyntaxProcessor}, + SetOptions[annotateSyntaxProcessor, "CommonestTypesAsTeXOptions" -> False]; + + Test[ + CellsToTeXPreamble["UseListings" -> Automatic] + , + "\\mmaSet{uselistings=false,morefv={gobble=2}}" + , + TestID -> "UseListings -> Automatic" + ] +] +Test[ + CellsToTeXPreamble["UseListings" -> True] + , + "\\mmaSet{uselistings=true,morefv={gobble=2}}" + , + TestID -> "UseListings -> True" +] +Test[ + CellsToTeXPreamble["UseListings" -> False] + , + "\\mmaSet{uselistings=false,morefv={gobble=2}}" + , + TestID -> "UseListings -> False" +] +Test[ + CellsToTeXPreamble["UseListings" -> None] + , + "\\mmaSet{morefv={gobble=2}}" + , + TestID -> "UseListings -> None" +] +Module[{unsupportedValue}, + With[ + { + heldMessage = + HoldForm @ Message[CellsToTeXException::unsupported, + HoldForm @ + CellsToTeXPreamble["UseListings" -> unsupportedValue], + HoldForm @ CellsToTeXException[ + "Unsupported", "OptionValue", "UseListings" + ], + HoldForm @ "OptionValue", + HoldForm @ unsupportedValue, + HoldForm @ {Automatic, True, False, None} + ] + } + , + TestMatch[ + CellsToTeXPreamble["UseListings" -> unsupportedValue] + , + Failure[ + CellsToTeXException[ + "Unsupported", "OptionValue", "UseListings" + ], + Association[ + "MessageTemplate" :> CellsToTeXException::unsupported, + "MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]] + ] + ] + , + {heldMessage} + , + TestID -> "UseListings -> unsupportedValue" + ] + ] +] + + +(* ::Subsection:: *) +(*TeXOptions option*) + + +Block[{opt1, opt2, val1, val2}, + Test[ + CellsToTeXPreamble["TeXOptions" -> {opt1 -> val1, opt2 :> val2}] + , + "\\mmaSet{morefv={gobble=2},opt1=val1,opt2=val2}" + , + TestID -> "TeXOptions -> Automatic" + ] +] +Module[{unsupportedValue}, + With[ + { + heldMessage = + HoldForm @ Message[CellsToTeXException::unsupported, + HoldForm @ + CellsToTeXPreamble["TeXOptions" -> unsupportedValue], + HoldForm @ CellsToTeXException[ + "Unsupported", "OptionValue", "TeXOptions" + ], + HoldForm @ "OptionValue", + HoldForm @ unsupportedValue, + HoldForm @ {"list of options"} + ] + } + , + TestMatch[ + CellsToTeXPreamble["TeXOptions" -> unsupportedValue] + , + Failure[ + CellsToTeXException["Unsupported", "OptionValue", "TeXOptions"] + , + Association[ + "MessageTemplate" :> CellsToTeXException::unsupported, + "MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]] + ] + ] + , + {heldMessage} + , + TestID -> "TeXOptions -> unsupportedValue" + ] + ] +] + + +(* ::Subsection:: *) +(*TeXMathReplacement option*) + + +Module[{testMathRepl}, + testMathRepl["test1"] = "testRepl1"; + testMathRepl["test2"] = "testRepl2"; + testMathRepl["test3"] = "testRepl3"; + + Test[ + CellsToTeXPreamble["TeXMathReplacement" -> testMathRepl] + , + "\ +\\mmaSet{morefv={gobble=2}} +\\mmaDefineMathReplacement{test1}{testRepl1} +\\mmaDefineMathReplacement{test2}{testRepl2} +\\mmaDefineMathReplacement{test3}{testRepl3}" + , + TestID -> "TeXMathReplacement -> testMathRepl" + ] +] +With[ + { + heldMessage = + HoldForm @ Message[CellsToTeXException::unsupported, + HoldForm @ CellsToTeXPreamble[ + "TeXMathReplacement" -> "unsupportedValue" + ], + HoldForm @ CellsToTeXException[ + "Unsupported", "OptionValue", "TeXMathReplacement" + ], + HoldForm @ "OptionValue", + HoldForm @ "unsupportedValue", + HoldForm @ {"a symbol"} + ] + } + , + TestMatch[ + CellsToTeXPreamble["TeXMathReplacement" -> "unsupportedValue"] + , + Failure[ + CellsToTeXException[ + "Unsupported", "OptionValue", "TeXMathReplacement" + ], + Association[ + "MessageTemplate" :> CellsToTeXException::unsupported, + "MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]] + ] + ] + , + {heldMessage} + , + TestID -> "TeXMathReplacement -> unsupportedValue" + ] +] + + +(* ::Subsection:: *) +(*Mixed options*) + + +Module[{testMathRepl}, + testMathRepl["x"] = "y"; + + Test[ + CellsToTeXPreamble[ + "TeXMathReplacement" -> testMathRepl, + "Gobble" -> 3, + "TeXOptions" -> {"a" -> "b"}, + "UseListings" -> True + ] + , + "\ +\\mmaSet{uselistings=true,morefv={gobble=3},a=b} +\\mmaDefineMathReplacement{x}{y}" + , + TestID -> "Mixed options" + ] +] + + +(* ::Section:: *) +(*TearDown*) + + +Unprotect["`*"] +Quiet[Remove["`*"], {Remove::rmnsm}] + + +EndPackage[] +$ContextPath = Rest[$ContextPath] diff --git a/CellsToTeX/Tests/Integration/fullNotebooks.mt b/CellsToTeX/Tests/Integration/fullNotebooks.mt new file mode 100644 index 0000000..3a4b719 --- /dev/null +++ b/CellsToTeX/Tests/Integration/fullNotebooks.mt @@ -0,0 +1,213 @@ +(* Mathematica Test File *) + +(* ::Section:: *) +(*SetUp*) + + +BeginPackage["CellsToTeX`Tests`Integration`fullNotebooks`", {"MUnit`"}] + + +Get["CellsToTeX`"] + +$ContextPath = + Join[{"CellsToTeX`Configuration`", "CellsToTeX`Backports`"}, $ContextPath] + + +testNb = + Notebook[{Cell[ + CellGroupData[ + { + Cell[ + BoxData @ MakeBoxes[ + Solve[ + a \[Chi]1^2 + \[Beta] \[Chi]1 + \[Gamma] == 0, + \[Chi]1 + ] + ], + "Input", + CellLabel -> "In[1]:=" + ] + , + Cell[ + BoxData @ MakeBoxes[{ + { + \[Chi]1 -> + (-\[Beta] - Sqrt[\[Beta]^2 - 4 a \[Gamma]]) / + (2 a) + }, + { + \[Chi]1 -> + (-\[Beta] + Sqrt[\[Beta]^2 - 4 a \[Gamma]]) / + (2 a) + } + }], + "Output", + CellLabel -> "Out[1]=" + ] + }, + Open + ] + ]}] + + +(* ::Section:: *) +(*Tests*) + + +Test[ + Clear[texMathReplacement]; + SetOptions[CellToTeX, "CurrentCellIndex" -> Automatic]; + StringJoin @ Riffle[ + Prepend[ + Cases[testNb, cell : Cell[_, __] :> CellToTeX[cell], Infinity], + CellsToTeXPreamble[] + ], + "\n\n" + ] + , + "\ +\\mmaSet{morefv={gobble=2}} + +\\begin{mmaCell}{Input} + Solve[a \\mmaSup{\\mmaFnc{\\(\\pmb{\\chi}\\)1}}{2}+\\mmaUnd{\\(\\pmb{\\beta}\\)} \\mmaFnc{\\(\\pmb{\\chi}\\)1}+\\mmaUnd{\\(\\pmb{\\gamma}\\)}==0,\\mmaFnc{\\(\\pmb{\\chi}\\)1}] +\\end{mmaCell} + +\\begin{mmaCell}{Output} + \\{\\{\\(\\chi\\)1\\(\\to\\)\\mmaFrac{-\\(\\beta\\)-\\mmaSqrt{\\mmaSup{\\(\\beta\\)}{2}-4 a \\(\\gamma\\)}}{2 a}\\},\\{\\(\\chi\\)1\\(\\to\\)\\mmaFrac{-\\(\\beta\\)+\\mmaSqrt{\\mmaSup{\\(\\beta\\)}{2}-4 a \\(\\gamma\\)}}{2 a}\\}\\} +\\end{mmaCell}" + , + TestID -> "Default" +] + + +Block[{$cellStyleOptions = $cellStyleOptions, Export = #1&}, + Test[ + $cellStyleOptions = + Join[ + { + {Except["Code"], "Processor"} -> + Composition[ + trackCellIndexProcessor, mmaCellGraphicsProcessor, + exportProcessor, cellLabelProcessor, + extractCellOptionsProcessor + ] + }, + $cellStyleOptions + ]; + Clear[texMathReplacement]; + SetOptions[CellToTeX, "CurrentCellIndex" -> Automatic]; + StringJoin @ Riffle[ + Prepend[ + Cases[testNb, + Cell[boxes_, style_, opts___] :> + CellToTeX @ Cell[ + boxes, Replace[style, "Input" -> "Code"], opts + ], + Infinity + ], + CellsToTeXPreamble[] + ], + "\n\n" + ] + , + "\ +\\mmaSet{morefv={gobble=2}} + +\\begin{mmaCell}{Code} + Solve[a*\\mmaFnc{\\[Chi]1}^2 + \\mmaUnd{\\[Beta]}*\\mmaFnc{\\[Chi]1} + \\mmaUnd{\\[Gamma]} == 0, \\mmaFnc{\\[Chi]1}] +\\end{mmaCell} + +\\mmaCellGraphics{Output}{756954b2.pdf}" + , + TestID -> "InputForm, pdf" + ] +] + + + +Block[{$stringsToTeX = $stringsToTeX}, + Test[ + Clear[texMathReplacement]; + SetOptions[CellToTeX, "CurrentCellIndex" -> Automatic]; + PrependTo[$stringsToTeX, "\[Equal]" -> "=="]; + StringJoin @ Riffle[ + Prepend[ + Cases[testNb, + cell : Cell[_, __] :> + CellToTeX[cell, "ProcessorOptions" -> { + "NonASCIIHandler" -> texMathReplacementRegister + }] + , + Infinity + ], + CellsToTeXPreamble[] + ], + "\n\n" + ] + , + "\ +\\mmaSet{morefv={gobble=2}} +\\mmaDefineMathReplacement{\[Beta]}{\\beta} +\\mmaDefineMathReplacement{\[Gamma]}{\\gamma} +\\mmaDefineMathReplacement{\[Chi]}{\\chi} +\\mmaDefineMathReplacement{\[Rule]}{\\to} + +\\begin{mmaCell}{Input} + Solve[a \\mmaSup{\\mmaFnc{\[Chi]1}}{2}+\\mmaUnd{\[Beta]} \\mmaFnc{\[Chi]1}+\\mmaUnd{\[Gamma]}==0,\\mmaFnc{\[Chi]1}] +\\end{mmaCell} + +\\begin{mmaCell}{Output} + \\{\\{\[Chi]1\[Rule]\\mmaFrac{-\[Beta]-\\mmaSqrt{\\mmaSup{\[Beta]}{2}-4 a \[Gamma]}}{2 a}\\},\\{\[Chi]1\[Rule]\\mmaFrac{-\[Beta]+\\mmaSqrt{\\mmaSup{\[Beta]}{2}-4 a \[Gamma]}}{2 a}\\}\\} +\\end{mmaCell}" + , + TestID -> "Math replacements" + ] +] + + +Test[ + Clear[texMathReplacement]; + SetOptions[CellToTeX, "CurrentCellIndex" -> Automatic]; + StringJoin @ Riffle[ + Prepend[ + Cases[testNb, + cell : Cell[_, __] :> + CellToTeX[cell, "ProcessorOptions" -> { + "CommonestTypesAsTeXOptions" -> False, + "BoxesToAnnotationTypes" -> + SyntaxAnnotations`$BoxesToAnnotationTypes, + "NonASCIIHandler" -> Identity + }] + , + Infinity + ], + CellsToTeXPreamble["UseListings" -> False] + ], + "\n\n" + ] + , + "\ +\\mmaSet{uselistings=false,morefv={gobble=2}} + +\\begin{mmaCell}{Input} + Solve[\\mmaUnd{a} \\mmaSup{\\mmaFnc{\[Chi]1}}{2}+\\mmaUnd{\[Beta]} \\mmaFnc{\[Chi]1}+\\mmaUnd{\[Gamma]}\[Equal]0,\\mmaFnc{\[Chi]1}] +\\end{mmaCell} + +\\begin{mmaCell}{Output} + \\{\\{\[Chi]1\[Rule]\\mmaFrac{-\[Beta]-\\mmaSqrt{\\mmaSup{\[Beta]}{2}-4 a \[Gamma]}}{2 a}\\},\\{\[Chi]1\[Rule]\\mmaFrac{-\[Beta]+\\mmaSqrt{\\mmaSup{\[Beta]}{2}-4 a \[Gamma]}}{2 a}\\}\\} +\\end{mmaCell}" + , + TestID -> "No listings" +] + + +(* ::Section:: *) +(*TearDown*) + + +Unprotect["`*"] +Quiet[Remove["`*"], {Remove::rmnsm}] + + +EndPackage[] +$ContextPath = Rest[$ContextPath] diff --git a/CellsToTeX/Tests/Integration/suite.mt b/CellsToTeX/Tests/Integration/suite.mt index c3aac9e..3f06028 100644 --- a/CellsToTeX/Tests/Integration/suite.mt +++ b/CellsToTeX/Tests/Integration/suite.mt @@ -11,5 +11,7 @@ TestSuite[{ "toInputFormProcessor.mt", "annotateSyntaxProcessor.mt", "mmaCellGraphicsProcessor.mt", - "CellToTeX.mt" + "CellToTeX.mt", + "CellsToTeXPreamble.mt", + "fullNotebooks.mt" }] \ No newline at end of file diff --git a/CellsToTeX/Tests/Unit/optionValueToTeX.mt b/CellsToTeX/Tests/Unit/optionValueToTeX.mt index dd9a248..677295d 100644 --- a/CellsToTeX/Tests/Unit/optionValueToTeX.mt +++ b/CellsToTeX/Tests/Unit/optionValueToTeX.mt @@ -18,6 +18,31 @@ PrependTo[$ContextPath, "CellsToTeX`Internal`"] (*Tests*) +Test[ + optionValueToTeX[""] + , + "" + , + TestID -> "empty string" +] + + +Test[ + optionValueToTeX[True] + , + "true" + , + TestID -> "True" +] +Test[ + optionValueToTeX[False] + , + "false" + , + TestID -> "False" +] + + Test[ optionValueToTeX[2] , @@ -129,6 +154,19 @@ Test[ ] +Test[ + optionValueToTeX[{ + "opt1" :> "[x]", + "opt2" -> {"opt2a" -> "val", "opt2b" -> True}, + "opt3" -> 5 + }] + , + "{opt1={[x]},opt2={opt2a=val,opt2b=true},opt3=5}" + , + TestID -> "nested list of options" +] + + (* ::Subsection:: *) (*Incorrect arguments*) diff --git a/CellsToTeX/Tests/Unit/optionsToTeX.mt b/CellsToTeX/Tests/Unit/optionsToTeX.mt index 8488143..46b2b6f 100644 --- a/CellsToTeX/Tests/Unit/optionsToTeX.mt +++ b/CellsToTeX/Tests/Unit/optionsToTeX.mt @@ -80,6 +80,22 @@ Test[ ] +Test[ + optionsToTeX[{ + "opt1" -> { + "opt1a" -> "{[a}", + "opt1b" :> -1, + "opt1c" -> {"opt1c1" :> False} + }, + "opt2" -> "" + }] + , + "opt1={opt1a={[a},opt1b=-1,opt1c={opt1c1=false}},opt2=" + , + TestID -> "nested" +] + + (* ::Subsection:: *) (*pre and post*) @@ -102,6 +118,15 @@ Test[ ] +Test[ + optionsToTeX["testPre3", {"name" :> {"subName" -> "val"}}, "testPost3"] + , + "testPre3name={subName=val}testPost3" + , + TestID -> "pre and post: nested" +] + + (* ::Subsection:: *) (*Incorrect arguments*) diff --git a/CellsToTeX/Tests/Unit/suite.mt b/CellsToTeX/Tests/Unit/suite.mt index 643a002..8bbb673 100644 --- a/CellsToTeX/Tests/Unit/suite.mt +++ b/CellsToTeX/Tests/Unit/suite.mt @@ -12,6 +12,7 @@ TestSuite[{ "headRulesToBoxRules.mt", "charToTeX.mt", "defaultAnnotationType.mt", + "texMathReplacementRegister.mt", "defaultOrFirst.mt", "commonestAnnotationTypes.mt", "annotationTypesToKeyVal.mt", diff --git a/CellsToTeX/Tests/Unit/texMathReplacementRegister.mt b/CellsToTeX/Tests/Unit/texMathReplacementRegister.mt new file mode 100644 index 0000000..87fc3e2 --- /dev/null +++ b/CellsToTeX/Tests/Unit/texMathReplacementRegister.mt @@ -0,0 +1,100 @@ +(* Mathematica Test File *) + +(* ::Section:: *) +(*SetUp*) + + +BeginPackage["CellsToTeX`Tests`Unit`texMathReplacementRegister`", {"MUnit`"}] + + +Get["CellsToTeX`"] + +PrependTo[$ContextPath, "CellsToTeX`Configuration`"] + + +(* ::Section:: *) +(*Tests*) + + +Block[{texMathReplacement}, + Test[ + texMathReplacementRegister["\[PlusMinus]"] + , + "\[PlusMinus]" + , + TestID -> "not defined: \\[PlusMinus]: texMathReplacementRegister" + ]; + Test[ + texMathReplacement // DownValues + , + {HoldPattern @ texMathReplacement["\[PlusMinus]"] :> "\\pm"} + , + TestID -> "not defined: \\[PlusMinus]: texMathReplacement DownValues" + ] +] + + +Block[{texMathReplacement}, + Test[ + texMathReplacementRegister["\[InvisibleSpace]"] + , + "\[InvisibleSpace]" + , + TestID -> + "not defined: \\[InvisibleSpace]: texMathReplacementRegister" + ]; + Test[ + texMathReplacement // DownValues + , + {} + , + TestID -> + "not defined: \\[InvisibleSpace]: texMathReplacement DownValues" + ] +] + + +Block[{texMathReplacement}, + texMathReplacement["\[Alpha]"] = "test old \[Alpha] replacement"; + + Test[ + texMathReplacementRegister["\[Alpha]"] + , + "\[Alpha]" + , + TestID -> "defined: \\[Alpha]: texMathReplacementRegister" + ]; + Test[ + texMathReplacement // DownValues + , + {HoldPattern @ texMathReplacement["\[Alpha]"] :> + "test old \[Alpha] replacement"} + , + TestID -> "defined: \\[Alpha]: texMathReplacement DownValues" + ] +] + + +(* ::Subsection:: *) +(*Protected attribute*) + + +Test[ + MemberQ[Attributes[texMathReplacementRegister], Protected] + , + True + , + TestID -> "Protected attribute" +] + + +(* ::Section:: *) +(*TearDown*) + + +Unprotect["`*"] +Quiet[Remove["`*"], {Remove::rmnsm}] + + +EndPackage[] +$ContextPath = Rest[$ContextPath] diff --git a/CellsToTeX/Tests/suite.mt b/CellsToTeX/Tests/suite.mt index 3039b8e..471ea63 100644 --- a/CellsToTeX/Tests/suite.mt +++ b/CellsToTeX/Tests/suite.mt @@ -12,6 +12,7 @@ TestSuite[{ "Unit/headRulesToBoxRules.mt", "Unit/charToTeX.mt", "Unit/defaultAnnotationType.mt", + "Unit/texMathReplacementRegister.mt", "Unit/defaultOrFirst.mt", "Unit/commonestAnnotationTypes.mt", "Unit/annotationTypesToKeyVal.mt", @@ -47,5 +48,7 @@ TestSuite[{ "Integration/toInputFormProcessor.mt", "Integration/annotateSyntaxProcessor.mt", "Integration/mmaCellGraphicsProcessor.mt", - "Integration/CellToTeX.mt" + "Integration/CellToTeX.mt", + "Integration/CellsToTeXPreamble.mt", + "Integration/fullNotebooks.mt" }] \ No newline at end of file