diff --git a/changelog.md b/changelog.md index f1ade603..ddfd9015 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,22 @@ texmath (unreleased) + * StarMath writer: avoid duplicate grouping braces in script arguments, + roots, accents, and brace labels. Reuse complete groups while preserving + grouping around inline fraction commands and compound expressions. + + * StarMath writer: separate upright letters from following identifiers + so `\mathrm d n` keeps only the differential upright, without extra braces. + + * StarMath writer: supply the missing operand for trailing plus/minus + signs demoted to ordinary symbols by TeX, as in `r_{j,+}` and `r_{j,-}`. + Use compact empty operands on both sides of plus/minus signs, and + handle standalone operators in fraction numerators and denominators. + + * StarMath writer: group annotated underbraces and overbraces so adjacent + terms do not become part of an earlier brace in LibreOffice. + Supply empty labels for bare braces and preserve centered scripts on + the opposite side of a brace, including `\underbrace{x}_{a}^2`. + * TeX reader: consume a single token for unbraced script arguments. For example, `x^12` and `x_12` now mean `x^{1}2` and `x_{1}2`, while braced multi-digit and decimal arguments remain intact. diff --git a/src/Text/TeXMath/Writers/StarMath.hs b/src/Text/TeXMath/Writers/StarMath.hs index e906c5f7..62b8f832 100644 --- a/src/Text/TeXMath/Writers/StarMath.hs +++ b/src/Text/TeXMath/Writers/StarMath.hs @@ -213,13 +213,14 @@ renderExpsIn dt ctx exps = do rendered <- mapM (renderExpIn dt ctx) exps let pieces = zip exps rendered let merged = mergePieces pieces - let withLhs = - if startsWithInfixNeedingLhs exps - then "{} " <> T.stripStart merged - else merged - pure $ if endsWithInfixNeedingRhs exps - then T.stripEnd withLhs <> " {}" - else withLhs + let withLhs = case exps of + e : _ | needsNeutralLhs e -> + (if isPlusMinusSign e then "{}" else "{} ") <> T.stripStart merged + _ -> merged + pure $ case reverse exps of + e : _ | needsNeutralRhs e -> + T.stripEnd withLhs <> (if isPlusMinusSign e then "{}" else " {}") + _ -> withLhs mergePieces :: [(Exp, T.Text)] -> T.Text mergePieces [] = "" @@ -288,6 +289,8 @@ needsSeparator prevE curE | isCloseLike prevE && isAccentCommandExp curE = True | isCloseLike prevE && isArrayLike curE = True | isIdentifierLike prevE && isWordStyledExp curE = True + -- Keep an upright letter from merging with the following identifier token. + | isUprightMathTextExp prevE && isIdentifierLike curE = True | isIdentifierLike prevE && isUprightMathTextExp curE = True | isIdentifierLike prevE && isAccentCommandExp curE = True | isIdentifierLike prevE && isWideSpace curE = True @@ -488,23 +491,19 @@ isLargeOpScriptedExp e = ESubsup base _ _ -> largeOpName base /= Nothing _ -> False -startsWithInfixNeedingLhs :: [Exp] -> Bool -startsWithInfixNeedingLhs exps = - case exps of - (e : _) -> needsNeutralLhs e - _ -> False - -endsWithInfixNeedingRhs :: [Exp] -> Bool -endsWithInfixNeedingRhs exps = - case reverse exps of - (e : _) -> needsNeutralRhs e - _ -> False - needsNeutralLhs :: Exp -> Bool needsNeutralLhs = isInfixLikeExp needsNeutralRhs :: Exp -> Bool -needsNeutralRhs = isInfixLikeExp +-- TeX demotes a trailing binary sign to Ord (for example in r_{j,+}). +-- StarMath still parses it as an operator and requires a right operand. +needsNeutralRhs e = isInfixLikeExp e || isPlusMinusSign e + +isPlusMinusSign :: Exp -> Bool +isPlusMinusSign e = + case e of + ESymbol _ s -> s == "+" || s == "-" || s == "−" + _ -> False needsNeutralScriptOperands :: Exp -> Bool needsNeutralScriptOperands e = @@ -547,8 +546,8 @@ renderExpIn dt ctx e = EStyled sty xs -> renderStyled dt ctx sty xs EFraction frac num den -> do - num' <- renderExpIn dt AlignDefault num - den' <- renderExpIn dt AlignDefault den + num' <- renderFractionArg dt num + den' <- renderFractionArg dt den let num'' = maybeCenterFractionArg ctx num' let den'' = maybeCenterFractionArg ctx den' pure $ case frac of @@ -558,11 +557,11 @@ renderExpIn dt ctx e = | dt == DisplayInline -> renderInlineFraction num'' den'' _ -> "{" <> num'' <> " over " <> den'' <> "}" - ESqrt x -> ("sqrt {" <>) . (<> "}") <$> renderExpIn dt ctx x + ESqrt x -> ("sqrt " <>) . groupArg dt x <$> renderExpIn dt ctx x ERoot idx rad -> do idx' <- renderExpIn dt ctx idx rad' <- renderExpIn dt ctx rad - pure $ "nroot {" <> idx' <> "} {" <> rad' <> "}" + pure $ "nroot " <> groupArg dt idx idx' <> " " <> groupArg dt rad rad' EScaled _ (ESymbol Open "|") -> Just "mline" @@ -601,6 +600,10 @@ renderExpIn dt ctx e = supRendered <- renderScriptArg dt ctx sup pure $ renderScriptBase base baseRendered <> "_" <> subRendered <> "^" <> supRendered + EOver _ (EOver _ base marker) over + | Nothing <- braceAnnotationName over + , Just brace <- braceAnnotationName marker -> + renderBrace dt ctx base brace over EOver _ base over | Just arrow <- arrowScriptOpName base -> do if isEmptyScriptArg over @@ -611,21 +614,24 @@ renderExpIn dt ctx e = | Just op <- centeredScriptOpName base -> do over' <- renderScriptArg dt ctx over pure $ "{" <> op <> "} csup " <> centerScriptArg over' - | Just brace <- braceAnnotationName over -> do - base' <- renderExpIn dt ctx base - pure $ renderScriptBase base base' <> " " <> brace + | Just brace <- braceAnnotationName over -> + renderBrace dt ctx base brace (EGrouped []) | isBraceAnnotatedExp base -> do base' <- renderExpIn dt ctx base - over' <- renderBraceLabel dt ctx over - pure $ base' <> " " <> over' + over' <- renderScriptArg dt ctx over + pure $ base' <> " csup " <> centerScriptArg over' | Just accent <- accentName over -> do base' <- renderExpIn dt ctx base - pure $ accent <> " " <> renderAccentArg base base' + pure $ accent <> " " <> renderAccentArg dt base base' | Just op <- limitOpName base -> do over' <- renderLimitArg dt ctx over pure $ op <> " to " <> over' <> " " | otherwise -> Nothing + EUnder _ (EUnder _ base marker) under + | Nothing <- braceAnnotationName under + , Just brace <- braceAnnotationName marker -> + renderBrace dt ctx base brace under EUnder _ base under -> case arrowScriptOpName base of Just arrow -> @@ -638,18 +644,17 @@ renderExpIn dt ctx e = case underlineMarkerName under of Just marker -> do base' <- renderExpIn dt ctx base - pure $ marker <> " " <> renderAccentArg base base' + pure $ marker <> " " <> renderAccentArg dt base base' Nothing -> case braceAnnotationName under of - Just brace -> do - base' <- renderExpIn dt ctx base - pure $ renderScriptBase base base' <> " " <> brace + Just brace -> + renderBrace dt ctx base brace (EGrouped []) Nothing -> if isBraceAnnotatedExp base then do base' <- renderExpIn dt ctx base - under' <- renderBraceLabel dt ctx under - pure $ base' <> " " <> under' + under' <- renderScriptArg dt ctx under + pure $ base' <> " csub " <> centerScriptArg under' else case centeredScriptOpName base of Just op -> do @@ -664,6 +669,16 @@ renderExpIn dt ctx e = base' <- renderExpIn dt ctx base under' <- renderScriptArg dt ctx under pure $ renderScriptBase base base' <> "_" <> under' + EUnderover _ (EUnder _ base marker) under over + | Just brace <- braceAnnotationName marker -> do + base' <- renderBrace dt ctx base brace under + over' <- renderScriptArg dt ctx over + pure $ base' <> " csup " <> centerScriptArg over' + EUnderover _ (EOver _ base marker) under over + | Just brace <- braceAnnotationName marker -> do + base' <- renderBrace dt ctx base brace over + under' <- renderScriptArg dt ctx under + pure $ base' <> " csub " <> centerScriptArg under' EUnderover _ base under over -> case arrowScriptOpName base of Just arrow -> @@ -1054,6 +1069,14 @@ asDelimitedArg t = then s else "{" <> s <> "}" +-- A single operator can be a fraction argument without an EGrouped wrapper. +-- Supply its missing operands within the argument, not around the fraction. +renderFractionArg :: DisplayType -> Exp -> Maybe T.Text +renderFractionArg dt e + | needsNeutralLhs e || needsNeutralRhs e = + ("{" <>) . (<> "}") <$> renderExpsIn dt AlignDefault [e] + | otherwise = renderExpIn dt AlignDefault e + renderInlineFraction :: T.Text -> T.Text -> T.Text renderInlineFraction num den = "size*0.7 {" <> num <> " over " <> den <> "}" @@ -1225,6 +1248,16 @@ renderScriptBase e rendered0 = then rendered else "{" <> rendered <> "}" +-- These constructors already render as one complete group. Other expressions +-- can start and end with braces without being grouped, e.g. {x} csub {a}. +groupArg :: DisplayType -> Exp -> T.Text -> T.Text +groupArg dt e rendered = + case e of + EGrouped{} -> rendered + EFraction DisplayFrac _ _ -> rendered + EFraction NormalFrac _ _ | dt == DisplayBlock -> rendered + _ -> "{" <> rendered <> "}" + renderScriptArg :: DisplayType -> AlignContext -> Exp -> Maybe T.Text renderScriptArg dt ctx e = do rendered0 <- @@ -1234,7 +1267,7 @@ renderScriptArg dt ctx e = do let rendered = T.strip rendered0 pure $ if (isAtomic e && not (needsNeutralScriptOperands e)) || isQuotedText rendered then rendered - else "{" <> rendered <> "}" + else groupArg dt e rendered renderPrimeSuffix :: Exp -> Maybe T.Text renderPrimeSuffix e = @@ -1271,12 +1304,12 @@ containsRelationLike = any isRelationLike EGrouped ys -> containsRelationLike ys _ -> False -renderAccentArg :: Exp -> T.Text -> T.Text -renderAccentArg e rendered0 = +renderAccentArg :: DisplayType -> Exp -> T.Text -> T.Text +renderAccentArg dt e rendered0 = let rendered = T.strip rendered0 in if isAtomic e then rendered - else "{" <> rendered <> "}" + else groupArg dt e rendered renderPhantomArg :: Exp -> T.Text -> T.Text renderPhantomArg e rendered0 = @@ -1340,13 +1373,24 @@ underlineMarkerName e = ESymbol TUnder "_" -> Just "underline" _ -> Nothing +-- StarMath braces require a label operand, even for an unannotated TeX brace. +-- Group the complete term so neither operand absorbs adjacent expressions. +renderBrace :: DisplayType -> AlignContext -> Exp -> T.Text -> Exp + -> Maybe T.Text +renderBrace dt ctx base brace label = do + base' <- renderExpIn dt ctx base + label' <- if isEmptyScriptArg label + then pure "{}" + else renderBraceLabel dt ctx label + pure $ "{" <> renderScriptBase base base' <> " " <> brace <> " " <> label' <> "}" + renderBraceLabel :: DisplayType -> AlignContext -> Exp -> Maybe T.Text renderBraceLabel dt ctx e = do rendered0 <- renderExpIn dt ctx e let rendered = T.strip rendered0 pure $ if isQuotedText rendered || isAtomic e then rendered - else "{" <> rendered <> "}" + else groupArg dt e rendered arrowScriptOpName :: Exp -> Maybe T.Text arrowScriptOpName e = diff --git a/test/writer/starmath/004_square_root.test b/test/writer/starmath/004_square_root.test index 5259a744..8b3cf523 100644 --- a/test/writer/starmath/004_square_root.test +++ b/test/writer/starmath/004_square_root.test @@ -1,4 +1,4 @@ <<< tex \sqrt{x+1} >>> starmath -sqrt {{x + 1}} +sqrt {x + 1} diff --git a/test/writer/starmath/01.test b/test/writer/starmath/01.test index 0ff0cd79..276ec9d3 100644 --- a/test/writer/starmath/01.test +++ b/test/writer/starmath/01.test @@ -19,4 +19,4 @@ (EGrouped [ ENumber "2" , EIdentifier "a" ]) ] >>> starmath -x = {{- b plusminus sqrt {{b^2 - 4ac}}} over {2a}} +x = {{- b plusminus sqrt {b^2 - 4ac}} over {2a}} diff --git a/test/writer/starmath/018_integral_with_infinite_upper_limit.test b/test/writer/starmath/018_integral_with_infinite_upper_limit.test index 1905eb61..d59413bb 100644 --- a/test/writer/starmath/018_integral_with_infinite_upper_limit.test +++ b/test/writer/starmath/018_integral_with_infinite_upper_limit.test @@ -1,4 +1,4 @@ <<< tex \int_{0}^{\infty} e^{-x}\,dx >>> starmath -int_0^infinity e^{{- x}} dx +int_0^infinity e^{- x} dx diff --git a/test/writer/starmath/026_greek_identifier_spacing_in_products.test b/test/writer/starmath/026_greek_identifier_spacing_in_products.test index 4afc5ebc..e6ad215d 100644 --- a/test/writer/starmath/026_greek_identifier_spacing_in_products.test +++ b/test/writer/starmath/026_greek_identifier_spacing_in_products.test @@ -1,4 +1,4 @@ <<< tex E_{k+1}=E_{k+\frac12}-\frac{\dot{Q}_{\text{dis},k}\Delta t}{\eta_{\text{dis}}}, >>> starmath -E_{{k + 1}} = E_{{k + {1 over 2}}} - {{{dot Q}_{{"dis", k}} %DELTA t} over %ieta_"dis"}, +E_{k + 1} = E_{k + {1 over 2}} - {{{dot Q}_{"dis", k} %DELTA t} over %ieta_"dis"}, diff --git a/test/writer/starmath/027_math_operators_rendered_as_functions.test b/test/writer/starmath/027_math_operators_rendered_as_functions.test index 33c695e8..09516449 100644 --- a/test/writer/starmath/027_math_operators_rendered_as_functions.test +++ b/test/writer/starmath/027_math_operators_rendered_as_functions.test @@ -1,4 +1,4 @@ <<< tex E_{k+1}\leftarrow\min\!\left(E^{\text{cap}}_{\text{s}},\max(0,E_{k+1})\right). >>> starmath -E_{{k + 1}} leftarrow func min left ( E_"s"^"cap", func max(0, E_{{k + 1}}) right ). +E_{k + 1} leftarrow func min left ( E_"s"^"cap", func max(0, E_{k + 1}) right ). diff --git a/test/writer/starmath/028_nested_function_with_left_delimiter_spacing.test b/test/writer/starmath/028_nested_function_with_left_delimiter_spacing.test index 4d00e1a9..95e57d57 100644 --- a/test/writer/starmath/028_nested_function_with_left_delimiter_spacing.test +++ b/test/writer/starmath/028_nested_function_with_left_delimiter_spacing.test @@ -1,4 +1,4 @@ <<< tex P_{\text{ch}, k}=\max\!\left(0,\min\!\left(P'_{\text{pv}, k},\,P^{\text{cap}}_{\text{ch}},\,P_{\text{ch,head}, k}\right)\right). >>> starmath -P_{{"ch", k}} = func max left ( 0, func min left ( P_{{"pv", k}}', P_"ch"^"cap", P_{{"ch,head", k}} right ) right ). +P_{"ch", k} = func max left ( 0, func min left ( P_{"pv", k}', P_"ch"^"cap", P_{"ch,head", k} right ) right ). diff --git a/test/writer/starmath/041_ordinary_function_with_subscript_keeps_ordinary_script_syntax.test b/test/writer/starmath/041_ordinary_function_with_subscript_keeps_ordinary_script_syntax.test index b360bb32..62d6e611 100644 --- a/test/writer/starmath/041_ordinary_function_with_subscript_keeps_ordinary_script_syntax.test +++ b/test/writer/starmath/041_ordinary_function_with_subscript_keeps_ordinary_script_syntax.test @@ -1,4 +1,4 @@ <<< tex \Delta\log_{10}K_j = \log_{10}K_{j,\mathrm{FPROPS}} - \log_{10}K_{j,\mathrm{ref}},\qquad j=1,\dots,r. >>> starmath -%DELTA log_10 K_j = log_10 K_{{j, "FPROPS"}} - log_10 K_{{j, "ref"}}, ~~ j = 1, dotslow , r. +%DELTA log_10 K_j = log_10 K_{j, "FPROPS"} - log_10 K_{j, "ref"}, ~~ j = 1, dotslow , r. diff --git a/test/writer/starmath/050_superscript_only_fragment_gets_neutral_base.test b/test/writer/starmath/050_superscript_only_fragment_gets_neutral_base.test index cbe849cd..27f5de29 100644 --- a/test/writer/starmath/050_superscript_only_fragment_gets_neutral_base.test +++ b/test/writer/starmath/050_superscript_only_fragment_gets_neutral_base.test @@ -1,4 +1,4 @@ <<< tex ^+ >>> starmath -{}^{{} + {}} +{}^{{}+{}} diff --git a/test/writer/starmath/051_grouped_subscript_only_fragment_gets_neutral_base.test b/test/writer/starmath/051_grouped_subscript_only_fragment_gets_neutral_base.test index 9a0db3ff..336eeec2 100644 --- a/test/writer/starmath/051_grouped_subscript_only_fragment_gets_neutral_base.test +++ b/test/writer/starmath/051_grouped_subscript_only_fragment_gets_neutral_base.test @@ -1,4 +1,4 @@ <<< tex _{j,\mathrm{ref}} >>> starmath -{}_{{j, "ref"}} +{}_{j, "ref"} diff --git a/test/writer/starmath/062_fallback_to_tex_for_under_over_constructs.test b/test/writer/starmath/062_fallback_to_tex_for_under_over_constructs.test index 30355aa0..4323825c 100644 --- a/test/writer/starmath/062_fallback_to_tex_for_under_over_constructs.test +++ b/test/writer/starmath/062_fallback_to_tex_for_under_over_constructs.test @@ -1,4 +1,4 @@ <<< tex \underbrace{x+y}_{z}+\overbrace{x+y}^{z} >>> starmath -{x + y} underbrace z + {x + y} overbrace z +{{x + y} underbrace z} + {{x + y} overbrace z} diff --git a/test/writer/starmath/066_standalone_plus_minus_scripts_get_neutral_operands.test b/test/writer/starmath/066_standalone_plus_minus_scripts_get_neutral_operands.test index 9663964d..9a48ed1e 100644 --- a/test/writer/starmath/066_standalone_plus_minus_scripts_get_neutral_operands.test +++ b/test/writer/starmath/066_standalone_plus_minus_scripts_get_neutral_operands.test @@ -1,4 +1,4 @@ <<< tex r_{r,e}=r_{r,e}^{+}-r_{r,e}^{-} >>> starmath -r_{{r, e}} = r_{{r, e}}^{{} + {}} - r_{{r, e}}^{{} - {}} +r_{r, e} = r_{r, e}^{{}+{}} - r_{r, e}^{{}-{}} diff --git a/test/writer/starmath/11.test b/test/writer/starmath/11.test index 4f095e10..686d4346 100644 --- a/test/writer/starmath/11.test +++ b/test/writer/starmath/11.test @@ -25,4 +25,4 @@ NormalFrac (ENumber "1") (ESub (EIdentifier "l") (ENumber "0")) ] >>> starmath -%iphi_n(%ikappa) = 0.033C_n^2 %ikappa^{{- 11 / 3}}, ~ {1 over L_0} ll %ikappa ll {1 over l_0} +%iphi_n(%ikappa) = 0.033C_n^2 %ikappa^{- 11 / 3}, ~ {1 over L_0} ll %ikappa ll {1 over l_0} diff --git a/test/writer/starmath/aligned_rate_contributions.test b/test/writer/starmath/aligned_rate_contributions.test new file mode 100644 index 00000000..b726525b --- /dev/null +++ b/test/writer/starmath/aligned_rate_contributions.test @@ -0,0 +1,10 @@ +<<< tex +\begin{aligned} +r_{j,\pm}^{0} +&=\underbrace{A_j\exp\!\left(-\frac{E_j}{R_{\mathrm u}T}\right)}_{k_j(T):\ \text{Arrhenius coefficient}} +\times\underbrace{(\text{gas factor})_{j,\pm}}_{\text{local hydrogen/steam}} +\times\underbrace{(\text{solid factor})_{j,\pm}}_{\text{inventory, presence and access}},\\ +r_j^0&=r_{j,+}^{0}-r_{j,-}^{0}. +\end{aligned} +>>> starmath +matrix { alignr r_{j, plusminus {}}^0 # alignl {} = {{A_j exp left ( -{{alignc {E_j}} over {alignc {R_{nitalic u} T}}} right )} underbrace {k_j(T) : "Arrhenius coefficient"}} times {{("gas factor")_{j, plusminus {}}} underbrace "local hydrogen/steam"} times {{("solid factor")_{j, plusminus {}}} underbrace "inventory, presence and access"}, ## alignr r_j^0 # alignl {} = r_{j, +{}}^0 - r_{j, -{}}^0. } diff --git a/test/writer/starmath/annotated_brace_product.test b/test/writer/starmath/annotated_brace_product.test new file mode 100644 index 00000000..6be1e012 --- /dev/null +++ b/test/writer/starmath/annotated_brace_product.test @@ -0,0 +1,7 @@ +<<< tex +\text{rate contribution} +=\underbrace{A_j\exp\!\left(-\frac{E_j}{R_{\mathrm u}T}\right)}_{k_j(T):\ \text{Arrhenius coefficient}} +\times\underbrace{\text{gas factor}}_{\text{local hydrogen/steam}} +\times\underbrace{\text{solid factor}}_{\text{inventory, presence and access}}. +>>> starmath +"rate contribution" = {{A_j exp left ( -{E_j over {R_{nitalic u} T}} right )} underbrace {k_j(T) : "Arrhenius coefficient"}} times {"gas factor" underbrace "local hydrogen/steam"} times {"solid factor" underbrace "inventory, presence and access"}. diff --git a/test/writer/starmath/annotated_brace_sum.test b/test/writer/starmath/annotated_brace_sum.test new file mode 100644 index 00000000..98d2bcf3 --- /dev/null +++ b/test/writer/starmath/annotated_brace_sum.test @@ -0,0 +1,4 @@ +<<< tex +1+\underbrace{x}_{a}+\underbrace{y}_{b}=\overbrace{x}^{c}+\overbrace{y}^{d}. +>>> starmath +1 + {x underbrace a} + {y underbrace b} = {x overbrace c} + {y overbrace d}. diff --git a/test/writer/starmath/bare_braces.test b/test/writer/starmath/bare_braces.test new file mode 100644 index 00000000..76a4324e --- /dev/null +++ b/test/writer/starmath/bare_braces.test @@ -0,0 +1,4 @@ +<<< tex +\overbrace{a}+b=\underbrace{x}+y +>>> starmath +{a overbrace {}} + b = {x underbrace {}} + y diff --git a/test/writer/starmath/bare_braces_inline.test b/test/writer/starmath/bare_braces_inline.test new file mode 100644 index 00000000..25e7403d --- /dev/null +++ b/test/writer/starmath/bare_braces_inline.test @@ -0,0 +1,4 @@ +<<< tex +\overbrace{a}+b=\underbrace{x}+y +>>> starmath-inline +{a overbrace {}} + b = {x underbrace {}} + y diff --git a/test/writer/starmath/brace_both_scripts.test b/test/writer/starmath/brace_both_scripts.test new file mode 100644 index 00000000..c7124872 --- /dev/null +++ b/test/writer/starmath/brace_both_scripts.test @@ -0,0 +1,4 @@ +<<< tex +\underbrace{x}_{a}^2+\overbrace{y}_{b}^{c} +>>> starmath +{x underbrace a} csup {2} + {y overbrace c} csub {b} diff --git a/test/writer/starmath/brace_both_scripts_inline.test b/test/writer/starmath/brace_both_scripts_inline.test new file mode 100644 index 00000000..48680030 --- /dev/null +++ b/test/writer/starmath/brace_both_scripts_inline.test @@ -0,0 +1,4 @@ +<<< tex +\underbrace{x}_{a}^2+\overbrace{y}_{b}^{c} +>>> starmath-inline +{x underbrace a} csup {2} + {y overbrace c} csub {b} diff --git a/test/writer/starmath/brace_opposite_scripts.test b/test/writer/starmath/brace_opposite_scripts.test new file mode 100644 index 00000000..aedc563b --- /dev/null +++ b/test/writer/starmath/brace_opposite_scripts.test @@ -0,0 +1,4 @@ +<<< tex +\underbrace{x}^{2}+\overbrace{y}_{b} +>>> starmath +{x underbrace {}} csup {2} + {y overbrace {}} csub {b} diff --git a/test/writer/starmath/brace_opposite_scripts_inline.test b/test/writer/starmath/brace_opposite_scripts_inline.test new file mode 100644 index 00000000..5babff9c --- /dev/null +++ b/test/writer/starmath/brace_opposite_scripts_inline.test @@ -0,0 +1,4 @@ +<<< tex +\underbrace{x}^{2}+\overbrace{y}_{b} +>>> starmath-inline +{x underbrace {}} csup {2} + {y overbrace {}} csub {b} diff --git a/test/writer/starmath/complex_number.test b/test/writer/starmath/complex_number.test index 60d72282..6a9e0876 100644 --- a/test/writer/starmath/complex_number.test +++ b/test/writer/starmath/complex_number.test @@ -24,4 +24,4 @@ (EText TextNormal "complex number") ] >>> starmath -c = {a underbrace "real" + {b nitalic i} underbrace "imaginary"} overbrace "complex number" +c = {{{a underbrace "real"} + {{b nitalic i} underbrace "imaginary"}} overbrace "complex number"} diff --git a/test/writer/starmath/compound_script_signs.test b/test/writer/starmath/compound_script_signs.test new file mode 100644 index 00000000..993d4270 --- /dev/null +++ b/test/writer/starmath/compound_script_signs.test @@ -0,0 +1,4 @@ +<<< tex +r_j^0=r_{j,+}^{0}-r_{j,-}^{0} +>>> starmath +r_j^0 = r_{j, +{}}^0 - r_{j, -{}}^0 diff --git a/test/writer/starmath/deMorgans_law.test b/test/writer/starmath/deMorgans_law.test index ae1c95a1..633a6a0d 100644 --- a/test/writer/starmath/deMorgans_law.test +++ b/test/writer/starmath/deMorgans_law.test @@ -38,4 +38,4 @@ (ESymbol TOver "\175") ] >>> starmath -neg (p and q) dlrarrow (neg p) or (neg q) overline {{oper ∪ from i = 1 to n A_i}} = oper ∩ from i = 1 to n overline {A_i} +neg (p and q) dlrarrow (neg p) or (neg q) overline {oper ∪ from i = 1 to n A_i} = oper ∩ from i = 1 to n overline {A_i} diff --git a/test/writer/starmath/differentiable_manifold.test b/test/writer/starmath/differentiable_manifold.test index a495ad3f..c197e682 100644 --- a/test/writer/starmath/differentiable_manifold.test +++ b/test/writer/starmath/differentiable_manifold.test @@ -67,4 +67,4 @@ ] ] >>> starmath -%igamma_1 equiv %igamma_2 dlrarrow left lbrace matrix { alignl %igamma_1(0) = %igamma_2(0) = p, " and " ## alignl {left none {{alignc {nitalic d}} over {alignc {nitalic dt}}}%iphi circ %igamma_1(t) right rline}_{{t = 0}} = {left none {{alignc {nitalic d}} over {alignc {nitalic dt}}}%iphi circ %igamma_2(t) right rline}_{{t = 0}} } right none +%igamma_1 equiv %igamma_2 dlrarrow left lbrace matrix { alignl %igamma_1(0) = %igamma_2(0) = p, " and " ## alignl {left none {{alignc {nitalic d}} over {alignc {nitalic d t}}}%iphi circ %igamma_1(t) right rline}_{t = 0} = {left none {{alignc {nitalic d}} over {alignc {nitalic d t}}}%iphi circ %igamma_2(t) right rline}_{t = 0} } right none diff --git a/test/writer/starmath/fraction_operator_arguments.test b/test/writer/starmath/fraction_operator_arguments.test new file mode 100644 index 00000000..8f958f36 --- /dev/null +++ b/test/writer/starmath/fraction_operator_arguments.test @@ -0,0 +1,4 @@ +<<< tex +\frac{a}{-}+\frac{a}{+}+\frac{-}{a}+\frac{a}{\pm}+\frac{a}{-b}+\frac{a}{b-c} +>>> starmath +{a over {{}-{}}} + {a over {{}+{}}} + {{{}-{}} over a} + {a over {{} plusminus {}}} + {a over {- b}} + {a over {b - c}} diff --git a/test/writer/starmath/fraction_operator_arguments_inline.test b/test/writer/starmath/fraction_operator_arguments_inline.test new file mode 100644 index 00000000..997e676a --- /dev/null +++ b/test/writer/starmath/fraction_operator_arguments_inline.test @@ -0,0 +1,4 @@ +<<< tex +\frac{a}{-}+\frac{a}{+}+\frac{-}{a}+\frac{a}{\pm}+\frac{a}{-b}+\frac{a}{b-c} +>>> starmath-inline +size*0.7 {a over {{}-{}}} + size*0.7 {a over {{}+{}}} + size*0.7 {{{}-{}} over a} + size*0.7 {a over {{} plusminus {}}} + size*0.7 {a over {- b}} + size*0.7 {a over {b - c}} diff --git a/test/writer/starmath/grouped_argument_boundaries.test b/test/writer/starmath/grouped_argument_boundaries.test new file mode 100644 index 00000000..3f0cb7f1 --- /dev/null +++ b/test/writer/starmath/grouped_argument_boundaries.test @@ -0,0 +1,4 @@ +<<< tex +\sqrt{x}y+\sqrt{x+y}z+x^{a+b}c+\sqrt{\underbrace{x}_{a}^2}+\hat{\overbrace{x}_{a}}+y^{\overbrace{x}_{a}} +>>> starmath +sqrt {x}y + sqrt {x + y}z + x^{a + b} c + sqrt {{x underbrace a} csup {2}} + hat {{x overbrace {}} csub {a}} + y^{{x overbrace {}} csub {a}} diff --git a/test/writer/starmath/grouped_argument_boundaries_inline.test b/test/writer/starmath/grouped_argument_boundaries_inline.test new file mode 100644 index 00000000..41a65b0d --- /dev/null +++ b/test/writer/starmath/grouped_argument_boundaries_inline.test @@ -0,0 +1,4 @@ +<<< tex +\sqrt{x}y+\sqrt{x+y}z+x^{a+b}c+\sqrt{\underbrace{x}_{a}^2}+\hat{\overbrace{x}_{a}}+y^{\overbrace{x}_{a}} +>>> starmath-inline +sqrt {x}y + sqrt {x + y}z + x^{a + b} c + sqrt {{x underbrace a} csup {2}} + hat {{x overbrace {}} csub {a}} + y^{{x overbrace {}} csub {a}} diff --git a/test/writer/starmath/grouped_arguments.test b/test/writer/starmath/grouped_arguments.test new file mode 100644 index 00000000..3d1c3174 --- /dev/null +++ b/test/writer/starmath/grouped_arguments.test @@ -0,0 +1,4 @@ +<<< tex +x^{a+b}+x_{i,j}+\sqrt{x+y}+\sqrt[1+k]{x+y}+\hat{x+y}+\underbrace{x}_{a+b} +>>> starmath +x^{a + b} + x_{i, j} + sqrt {x + y} + nroot {1 + k} {x + y} + hat {x + y} + {x underbrace {a + b}} diff --git a/test/writer/starmath/grouped_arguments_inline.test b/test/writer/starmath/grouped_arguments_inline.test new file mode 100644 index 00000000..3229a1c8 --- /dev/null +++ b/test/writer/starmath/grouped_arguments_inline.test @@ -0,0 +1,4 @@ +<<< tex +x^{a+b}+x_{i,j}+\sqrt{x+y}+\sqrt[1+k]{x+y}+\hat{x+y}+\underbrace{x}_{a+b} +>>> starmath-inline +x^{a + b} + x_{i, j} + sqrt {x + y} + nroot {1 + k} {x + y} + hat {x + y} + {x underbrace {a + b}} diff --git a/test/writer/starmath/grouped_fraction_arguments.test b/test/writer/starmath/grouped_fraction_arguments.test new file mode 100644 index 00000000..19d40e6d --- /dev/null +++ b/test/writer/starmath/grouped_fraction_arguments.test @@ -0,0 +1,4 @@ +<<< tex +\sqrt{\frac{a}{b}}+\sqrt{\tfrac{a}{b}}+\sqrt{\dfrac{a}{b}}+\sqrt{\binom{a}{b}}+x^{\frac{a}{b}}+\underbrace{x}_{\frac{a}{b}} +>>> starmath +sqrt {a over b} + sqrt {size*0.7 {a over b}} + sqrt {a over b} + sqrt {left ( binom{a}{b} right )} + x^{a over b} + {x underbrace {a over b}} diff --git a/test/writer/starmath/grouped_fraction_arguments_inline.test b/test/writer/starmath/grouped_fraction_arguments_inline.test new file mode 100644 index 00000000..626c1d1b --- /dev/null +++ b/test/writer/starmath/grouped_fraction_arguments_inline.test @@ -0,0 +1,4 @@ +<<< tex +\sqrt{\frac{a}{b}}+\sqrt{\tfrac{a}{b}}+\sqrt{\dfrac{a}{b}}+\sqrt{\binom{a}{b}}+x^{\frac{a}{b}}+\underbrace{x}_{\frac{a}{b}} +>>> starmath-inline +sqrt {size*0.7 {a over b}} + sqrt {size*0.7 {a over b}} + sqrt {a over b} + sqrt {left ( binom{a}{b} right )} + x^{size*0.7 {a over b}} + {x underbrace {size*0.7 {a over b}}} diff --git a/test/writer/starmath/moore_determinant.test b/test/writer/starmath/moore_determinant.test index 230b1724..b3aeee2e 100644 --- a/test/writer/starmath/moore_determinant.test +++ b/test/writer/starmath/moore_determinant.test @@ -51,4 +51,4 @@ ] ] >>> starmath -M = left [ matrix { %ialpha_1 # %ialpha_1^q # dotsaxis # %ialpha_1^{q^{{n - 1}}} ## %ialpha_2 # %ialpha_2^q # dotsaxis # %ialpha_2^{q^{{n - 1}}} ## dotsvert # dotsvert # {} dotsdown {} # dotsvert ## %ialpha_m # %ialpha_m^q # dotsaxis # %ialpha_m^{q^{{n - 1}}} } right ] +M = left [ matrix { %ialpha_1 # %ialpha_1^q # dotsaxis # %ialpha_1^{q^{n - 1}} ## %ialpha_2 # %ialpha_2^q # dotsaxis # %ialpha_2^{q^{n - 1}} ## dotsvert # dotsvert # {} dotsdown {} # dotsvert ## %ialpha_m # %ialpha_m^q # dotsaxis # %ialpha_m^{q^{n - 1}} } right ] diff --git a/test/writer/starmath/nested_bare_braces.test b/test/writer/starmath/nested_bare_braces.test new file mode 100644 index 00000000..d6819cbe --- /dev/null +++ b/test/writer/starmath/nested_bare_braces.test @@ -0,0 +1,4 @@ +<<< tex +\overbrace{\overbrace{x}}+\underbrace{\underbrace{y}}+\overbrace{\underbrace{z}_{a}}^{b} +>>> starmath +{{x overbrace {}} overbrace {}} + {{y underbrace {}} underbrace {}} + {{z underbrace a} overbrace b} diff --git a/test/writer/starmath/operatorname.test b/test/writer/starmath/operatorname.test index f0489d8b..1b58f2bb 100644 --- a/test/writer/starmath/operatorname.test +++ b/test/writer/starmath/operatorname.test @@ -68,4 +68,4 @@ ] ] >>> starmath -left lbrace matrix { alignl func div_x u func div^x u func div_x^y u func div_x^y u # alignl "operatorname" ## alignl {func "⋆-lim'sup"} csub {{x toward 0}} u {func "⋆-lim'sup"} csup {w} u {func "⋆-lim'sup"} csub {{x toward 0}} csup {w} u {func "⋆-lim'sup"} csub {{x toward 0}} csup {w} u # alignl "operatorname*" ## alignl func "⋆-lim'sup"_{{x toward 0}} u func "⋆-lim'sup"^w u func "⋆-lim'sup"_{{x toward 0}}^w u func "⋆-lim'sup"_{{x toward 0}}^w u # alignl "operatorname*:nolimits" ## alignl func curl_x v {func argmax} csub {K} u # alignl "DeclareMathOperator" } right none +left lbrace matrix { alignl func div_x u func div^x u func div_x^y u func div_x^y u # alignl "operatorname" ## alignl {func "⋆-lim'sup"} csub {x toward 0} u {func "⋆-lim'sup"} csup {w} u {func "⋆-lim'sup"} csub {x toward 0} csup {w} u {func "⋆-lim'sup"} csub {x toward 0} csup {w} u # alignl "operatorname*" ## alignl func "⋆-lim'sup"_{x toward 0} u func "⋆-lim'sup"^w u func "⋆-lim'sup"_{x toward 0}^w u func "⋆-lim'sup"_{x toward 0}^w u # alignl "operatorname*:nolimits" ## alignl func curl_x v {func argmax} csub {K} u # alignl "DeclareMathOperator" } right none diff --git a/test/writer/starmath/quadratic_formula.test b/test/writer/starmath/quadratic_formula.test index 0ff0cd79..276ec9d3 100644 --- a/test/writer/starmath/quadratic_formula.test +++ b/test/writer/starmath/quadratic_formula.test @@ -19,4 +19,4 @@ (EGrouped [ ENumber "2" , EIdentifier "a" ]) ] >>> starmath -x = {{- b plusminus sqrt {{b^2 - 4ac}}} over {2a}} +x = {{- b plusminus sqrt {b^2 - 4ac}} over {2a}} diff --git a/test/writer/starmath/root_token_boundaries.test b/test/writer/starmath/root_token_boundaries.test new file mode 100644 index 00000000..d0e8022f --- /dev/null +++ b/test/writer/starmath/root_token_boundaries.test @@ -0,0 +1,4 @@ +<<< tex +\sqrt xy+\sqrt{x}y+\sqrt{xy}+\sqrt12+\sqrt{12} +>>> starmath +sqrt {x}y + sqrt {x}y + sqrt {xy} + sqrt {1}2 + sqrt {12} diff --git a/test/writer/starmath/root_token_boundaries_inline.test b/test/writer/starmath/root_token_boundaries_inline.test new file mode 100644 index 00000000..19e19954 --- /dev/null +++ b/test/writer/starmath/root_token_boundaries_inline.test @@ -0,0 +1,4 @@ +<<< tex +\sqrt xy+\sqrt{x}y+\sqrt{xy}+\sqrt12+\sqrt{12} +>>> starmath-inline +sqrt {x}y + sqrt {x}y + sqrt {xy} + sqrt {1}2 + sqrt {12} diff --git a/test/writer/starmath/script_signs_and_arithmetic.test b/test/writer/starmath/script_signs_and_arithmetic.test new file mode 100644 index 00000000..c1559984 --- /dev/null +++ b/test/writer/starmath/script_signs_and_arithmetic.test @@ -0,0 +1,4 @@ +<<< tex +r_{j,+}+r_{j,-}+r_{j,\pm}+x^{-1}+x^{n-1}+x^{-}+x^{+} +>>> starmath +r_{j, +{}} + r_{j, -{}} + r_{j, plusminus {}} + x^{- 1} + x^{n - 1} + x^{{}-{}} + x^{{}+{}} diff --git a/test/writer/starmath/script_token_boundaries.test b/test/writer/starmath/script_token_boundaries.test index 9f01b442..a6ec86b0 100644 --- a/test/writer/starmath/script_token_boundaries.test +++ b/test/writer/starmath/script_token_boundaries.test @@ -1,4 +1,4 @@ <<< tex -x^12+x^{1}2+x^{12}+x_12+x_{1}2+x_{12} +x^ab+x^{a}b+x^{ab}+x_ab+x_{a}b+x_{ab}+x^12+x^{1}2+x^{12}+x_12+x_{1}2+x_{12}+x_a^bc+x_ab^c >>> starmath -x^1 2 + x^1 2 + x^12 + x_1 2 + x_1 2 + x_12 +x^a b + x^a b + x^{ab} + x_a b + x_a b + x_{ab} + x^1 2 + x^1 2 + x^12 + x_1 2 + x_1 2 + x_12 + x_a^b c + x_a b^c diff --git a/test/writer/starmath/script_token_boundaries_inline.test b/test/writer/starmath/script_token_boundaries_inline.test index f1bc7c7d..9e4816f8 100644 --- a/test/writer/starmath/script_token_boundaries_inline.test +++ b/test/writer/starmath/script_token_boundaries_inline.test @@ -1,4 +1,4 @@ <<< tex -x^12+x^{1}2+x^{12}+x_12+x_{1}2+x_{12} +x^ab+x^{a}b+x^{ab}+x_ab+x_{a}b+x_{ab}+x^12+x^{1}2+x^{12}+x_12+x_{1}2+x_{12}+x_a^bc+x_ab^c >>> starmath-inline -x^1 2 + x^1 2 + x^12 + x_1 2 + x_1 2 + x_12 +x^a b + x^a b + x^{ab} + x_a b + x_a b + x_{ab} + x^1 2 + x^1 2 + x^12 + x_1 2 + x_1 2 + x_12 + x_a^b c + x_a b^c diff --git a/test/writer/starmath/sophomores_dream.test b/test/writer/starmath/sophomores_dream.test index 4b0010dd..193b280a 100644 --- a/test/writer/starmath/sophomores_dream.test +++ b/test/writer/starmath/sophomores_dream.test @@ -24,4 +24,4 @@ ] ] >>> starmath -int_0^1 x^x nitalic dx = sum from n = 1 to infinity {(- 1)^{{n + 1}} n^{{- n}}} +int_0^1 x^x nitalic d x = sum from n = 1 to infinity {(- 1)^{n + 1} n^{- n}} diff --git a/test/writer/starmath/sphere_volume.test b/test/writer/starmath/sphere_volume.test index 4dafb9ad..6324ae87 100644 --- a/test/writer/starmath/sphere_volume.test +++ b/test/writer/starmath/sphere_volume.test @@ -124,4 +124,4 @@ ] ] >>> starmath -S = left lbrace 0 <= %iphi <= 2%ipi , 0 <= %itheta <= %ipi , 0 <= %irho <= R right rbrace matrix { alignr "Volume" # alignl {} = iiint from S %irho^2 sin %itheta nitalic d%irho nitalic d%itheta nitalic d%iphi ## alignr {} # alignl {} = int_0^{{2%ipi}} nitalic d%iphi int_0^%ipi sin %itheta nitalic d%itheta int_0^R %irho^2 nitalic d%irho ## alignr {} # alignl {} = {left none %iphi right rline}_0^{{2%ipi}} {left none left ( - cos %itheta right ) right rline}_0^%ipi size*0.7 {{alignc 1} over {alignc 3}}{left none %irho^3 right rline}_0^R ## alignr {} # alignl {} = 2%ipi times 2 times size*0.7 {{alignc 1} over {alignc 3}}R^3 ## alignr {} # alignl {} = size*0.7 {{alignc 4} over {alignc 3}}%ipi R^3 } +S = left lbrace 0 <= %iphi <= 2%ipi , 0 <= %itheta <= %ipi , 0 <= %irho <= R right rbrace matrix { alignr "Volume" # alignl {} = iiint from S %irho^2 sin %itheta nitalic d %irho nitalic d %itheta nitalic d %iphi ## alignr {} # alignl {} = int_0^{2%ipi} nitalic d %iphi int_0^%ipi sin %itheta nitalic d %itheta int_0^R %irho^2 nitalic d %irho ## alignr {} # alignl {} = {left none %iphi right rline}_0^{2%ipi} {left none left ( - cos %itheta right ) right rline}_0^%ipi size*0.7 {{alignc 1} over {alignc 3}}{left none %irho^3 right rline}_0^R ## alignr {} # alignl {} = 2%ipi times 2 times size*0.7 {{alignc 1} over {alignc 3}}R^3 ## alignr {} # alignl {} = size*0.7 {{alignc 4} over {alignc 3}}%ipi R^3 } diff --git a/test/writer/starmath/subsup.test b/test/writer/starmath/subsup.test index 1242b029..5367eb1b 100644 --- a/test/writer/starmath/subsup.test +++ b/test/writer/starmath/subsup.test @@ -65,4 +65,4 @@ , ESubsup (ESpace (1 % 1)) (EIdentifier "x") (ENumber "3") ] >>> starmath -x_b^a ~ x_b^a ~ {func min} csub {A}~ {func max} csub {B}~ {func det} csub {C}~ {func Pr} csub {A}~ {func gcd} csub {A}~ {dot u}^2 ~ {overline u}_%ivarepsilon ~ {underline u}_b^a ~ {a + b} overbrace "term"~ {a + b} overbrace c~ {a + b} underbrace c~ {a + b} underbrace c{~}^H e3{~}_x A{~}_x^3 +x_b^a ~ x_b^a ~ {func min} csub {A}~ {func max} csub {B}~ {func det} csub {C}~ {func Pr} csub {A}~ {func gcd} csub {A}~ {dot u}^2 ~ {overline u}_%ivarepsilon ~ {underline u}_b^a ~ {{a + b} overbrace "term"}~ {{a + b} overbrace c}~ {{a + b} underbrace c}~ {{a + b} underbrace c}{~}^H e3{~}_x A{~}_x^3 diff --git a/test/writer/starmath/upright_differential_fraction.test b/test/writer/starmath/upright_differential_fraction.test new file mode 100644 index 00000000..223d3620 --- /dev/null +++ b/test/writer/starmath/upright_differential_fraction.test @@ -0,0 +1,4 @@ +<<< tex +\frac{\mathrm d n_i}{\mathrm d t} +>>> starmath +{{nitalic d n_i} over {nitalic d t}} diff --git a/test/writer/starmath/upright_identifier_boundaries.test b/test/writer/starmath/upright_identifier_boundaries.test new file mode 100644 index 00000000..8c79fa17 --- /dev/null +++ b/test/writer/starmath/upright_identifier_boundaries.test @@ -0,0 +1,4 @@ +<<< tex +\mathrm d n+\mathrm d n_i+\mathrm d n^2+\mathrm d 2+\mathrm d\alpha+\mathrm d+\mathrm{dt}+\frac{\mathrm d}{t} +>>> starmath +nitalic d n + nitalic d n_i + nitalic d n^2 + nitalic d 2 + nitalic d %ialpha + nitalic d + "dt" + {nitalic d over t} diff --git a/test/writer/starmath/upright_rate_equations.test b/test/writer/starmath/upright_rate_equations.test new file mode 100644 index 00000000..fdb3465c --- /dev/null +++ b/test/writer/starmath/upright_rate_equations.test @@ -0,0 +1,9 @@ +<<< tex +\frac{\mathrm d n_i}{\mathrm d t}=n_*\sum_{j\in\{1,2,3,Q,F\}}\nu_{ij}r_j, +\qquad +\begin{aligned} +\frac{\mathrm d n_W}{\mathrm d t}&=n_*(3r_2-r_3-2r_Q),\\ +\frac{\mathrm d n_F}{\mathrm d t}&=n_*(r_Q-r_F). +\end{aligned} +>>> starmath +{{nitalic d n_i} over {nitalic d t}} = n_{{} * {}}sum from j in left lbrace 1, 2, 3, Q, F right rbrace %inu_{ij} r_j, ~~ matrix { alignr {{alignc {nitalic d n_W}} over {alignc {nitalic d t}}} # alignl {} = n_{{} * {}}(3r_2 - r_3 - 2r_Q), ## alignr {{alignc {nitalic d n_F}} over {alignc {nitalic d t}}} # alignl {} = n_{{} * {}}(r_Q - r_F). }