@copylee/dsh-office 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helper/OfficeHelper.cs +44 -3
- package/package.json +1 -1
package/helper/OfficeHelper.cs
CHANGED
|
@@ -803,7 +803,7 @@ static class Program
|
|
|
803
803
|
{ "Sigma", "Σ" }, { "Phi", "Φ" }, { "Psi", "Ψ" }, { "Omega", "Ω" },
|
|
804
804
|
{ "cdot", "⋅" }, { "times", "×" }, { "div", "÷" }, { "pm", "±" }, { "mp", "∓" }, { "approx", "≈" }, { "neq", "≠" }, { "ne", "≠" },
|
|
805
805
|
{ "leq", "≤" }, { "le", "≤" }, { "geq", "≥" }, { "ge", "≥" }, { "ll", "≪" }, { "gg", "≫" }, { "equiv", "≡" }, { "propto", "∝" }, { "sim", "∼" },
|
|
806
|
-
{ "infty", "∞" }, { "partial", "∂" }, { "nabla", "∇" }, { "sum", "∑" }, { "prod", "∏" }, { "int", "∫" }, { "oint", "∮" },
|
|
806
|
+
{ "infty", "∞" }, { "partial", "∂" }, { "nabla", "∇" }, { "sum", "∑" }, { "prod", "∏" }, { "int", "∫" }, { "oint", "∮" }, { "iint", "∬" }, { "iiint", "∭" }, { "oiint", "∯" },
|
|
807
807
|
{ "to", "→" }, { "rightarrow", "→" }, { "leftarrow", "←" }, { "Rightarrow", "⇒" }, { "Leftrightarrow", "⇔" }, { "in", "∈" }, { "notin", "∉" },
|
|
808
808
|
{ "subset", "⊂" }, { "cup", "∪" }, { "cap", "∩" }, { "forall", "∀" }, { "exists", "∃" }, { "angle", "∠" }, { "perp", "⊥" }, { "parallel", "∥" },
|
|
809
809
|
{ "circ", "∘" }, { "degree", "°" }, { "ldots", "…" }, { "cdots", "⋯" }, { "dots", "…" }, { "prime", "′" }, { "hbar", "ℏ" }, { "ell", "ℓ" },
|
|
@@ -855,13 +855,22 @@ static class Program
|
|
|
855
855
|
{
|
|
856
856
|
StringBuilder o = new StringBuilder();
|
|
857
857
|
int i = 0;
|
|
858
|
+
// Integral signs written one after another are one multiple integral.
|
|
859
|
+
if (s.IndexOf("\\int", StringComparison.Ordinal) >= 0)
|
|
860
|
+
{
|
|
861
|
+
s = System.Text.RegularExpressions.Regex.Replace(s, @"\\int(?:\s|\\!)*\\int(?:\s|\\!)*\\int(?![a-zA-Z])", "\\iiint");
|
|
862
|
+
s = System.Text.RegularExpressions.Regex.Replace(s, @"\\int(?:\s|\\!)*\\int(?![a-zA-Z])", "\\iint");
|
|
863
|
+
}
|
|
858
864
|
// A sum, product or integral was written and its limits may still follow; what comes after them is its
|
|
859
865
|
// operand, which Word's linear format introduces with "▒" (left out, Word draws an empty box there).
|
|
860
866
|
bool nary = false;
|
|
861
867
|
while (i < s.Length)
|
|
862
868
|
{
|
|
863
869
|
char c = s[i];
|
|
864
|
-
|
|
870
|
+
// Nothing may stand between the limits and "▒": a space there ends the operator with an empty operand.
|
|
871
|
+
if (nary && c == ' ') { i++; continue; }
|
|
872
|
+
if (nary && c == '\\' && i + 1 < s.Length && ",;:! ".IndexOf(s[i + 1]) >= 0) { i += 2; continue; }
|
|
873
|
+
if (nary && c != '^' && c != '_')
|
|
865
874
|
{
|
|
866
875
|
if (c == '\\' && string.CompareOrdinal(s, i, "\\limits", 0, 7) == 0) { i += 7; continue; }
|
|
867
876
|
if (c == '\\' && string.CompareOrdinal(s, i, "\\nolimits", 0, 9) == 0) { i += 9; continue; }
|
|
@@ -953,8 +962,10 @@ static class Program
|
|
|
953
962
|
string symbol;
|
|
954
963
|
if (TexSymbols.TryGetValue(name, out symbol))
|
|
955
964
|
{
|
|
965
|
+
// A function name right after a letter (r\cos u) would be read as one word with it.
|
|
966
|
+
if (symbol.Length > 1 && symbol == name && o.Length > 0 && char.IsLetter(o[o.Length - 1])) o.Append(' ');
|
|
956
967
|
o.Append(symbol);
|
|
957
|
-
if (symbol == "∑" || symbol == "∏" || symbol == "∫" || symbol == "∮") nary = true;
|
|
968
|
+
if (symbol == "∑" || symbol == "∏" || symbol == "∫" || symbol == "∮" || symbol == "∬" || symbol == "∭" || symbol == "∯") nary = true;
|
|
958
969
|
// A function name is applied to what follows: Word needs a space after it.
|
|
959
970
|
if (symbol.Length > 1 && symbol == name && i < s.Length && s[i] != ' ' && s[i] != '^' && s[i] != '_') o.Append(' ');
|
|
960
971
|
}
|
|
@@ -1007,11 +1018,40 @@ static class Program
|
|
|
1007
1018
|
return made;
|
|
1008
1019
|
}
|
|
1009
1020
|
|
|
1021
|
+
/// Equations on a line of their own built during the current operation (their ranges: these keep pointing at the
|
|
1022
|
+
/// equation while the document grows). They are set off from the text once the operation is done: a paragraph
|
|
1023
|
+
/// inserted after one takes over its look, and must not take over this.
|
|
1024
|
+
static readonly List<object> Displays = new List<object>();
|
|
1025
|
+
|
|
1026
|
+
/// As typeset papers do: some space above and below the equation, and a line that grows with the formula
|
|
1027
|
+
/// (an exact line height would cut a tall one off).
|
|
1028
|
+
static void SetOff()
|
|
1029
|
+
{
|
|
1030
|
+
foreach (dynamic equation in Displays)
|
|
1031
|
+
{
|
|
1032
|
+
try
|
|
1033
|
+
{
|
|
1034
|
+
dynamic paragraph = equation.Paragraphs[1];
|
|
1035
|
+
dynamic range = paragraph.Range;
|
|
1036
|
+
dynamic math = range.OMaths[1].Range;
|
|
1037
|
+
if ((int)range.OMaths.Count != 1) continue;
|
|
1038
|
+
if ((int)range.End - (int)range.Start > (int)math.End - (int)math.Start + 3) continue;
|
|
1039
|
+
dynamic format = paragraph.Format;
|
|
1040
|
+
if ((float)format.SpaceBefore < 6f) format.SpaceBefore = 6f;
|
|
1041
|
+
if ((float)format.SpaceAfter < 6f) format.SpaceAfter = 6f;
|
|
1042
|
+
if ((int)format.LineSpacingRule == 4) format.LineSpacingRule = 3;
|
|
1043
|
+
}
|
|
1044
|
+
catch (Exception) { }
|
|
1045
|
+
}
|
|
1046
|
+
Displays.Clear();
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1010
1049
|
/// Formulas that could not be turned into equations during the current operation (they stay as text).
|
|
1011
1050
|
static int MathFailed;
|
|
1012
1051
|
|
|
1013
1052
|
static string MathNote()
|
|
1014
1053
|
{
|
|
1054
|
+
SetOff();
|
|
1015
1055
|
if (MathFailed == 0) return "";
|
|
1016
1056
|
string note = " — NOTE " + MathFailed + " formula(s) could not be built and were left as text: check them with office_render and rewrite them more simply";
|
|
1017
1057
|
MathFailed = 0;
|
|
@@ -1039,6 +1079,7 @@ static class Program
|
|
|
1039
1079
|
dynamic math = doc.OMaths.Add(spot);
|
|
1040
1080
|
math.OMaths[1].BuildUp();
|
|
1041
1081
|
if (display) { try { math.OMaths[1].Type = 0; math.OMaths[1].Justification = 1; } catch (COMException) { } }
|
|
1082
|
+
if (display) { try { Displays.Add(math.OMaths[1].Range); } catch (Exception) { } }
|
|
1042
1083
|
return true;
|
|
1043
1084
|
}
|
|
1044
1085
|
catch (COMException) { return false; }
|
package/package.json
CHANGED