Skip to content

Commit 22e8ab5

Browse files
authored
Merge branch 'master' into improve_latex_form
2 parents ee7e525 + 2b61d48 commit 22e8ab5

4 files changed

Lines changed: 94 additions & 1 deletion

File tree

mathics/builtin/box/layout.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def eval_tagbox(self, expr, form: Symbol, evaluation: Evaluation):
147147
assert isinstance(expr, BoxElementMixin), f"{expr}"
148148
return FormBox(expr, form, **options)
149149

150+
@property
151+
def is_multiline(self) -> bool:
152+
return self.boxes.is_multiline
153+
150154

151155
class FractionBox(BoxExpression):
152156
"""
@@ -335,6 +339,10 @@ def eval_display(self, boxexpr, evaluation):
335339
"""DisplayForm[boxexpr_InterpretationBox]"""
336340
return boxexpr.boxes
337341

342+
@property
343+
def is_multiline(self) -> bool:
344+
return self.boxes.is_multiline
345+
338346

339347
class PaneBox(BoxExpression):
340348
"""
@@ -379,6 +387,10 @@ def eval_display(boxexpr, evaluation):
379387
"""DisplayForm[boxexpr_PaneBox]"""
380388
return boxexpr.elements[0]
381389

390+
@property
391+
def is_multiline(self) -> bool:
392+
return self.boxes.is_multiline
393+
382394

383395
class RowBox(BoxExpression):
384396
"""
@@ -445,6 +457,10 @@ def check_item(item):
445457

446458
self.items = tuple((check_item(item) for item in items))
447459

460+
@property
461+
def is_multiline(self) -> bool:
462+
return any(item.is_multiline for item in self.items)
463+
448464

449465
class ShowStringCharacters(Builtin):
450466
"""
@@ -587,6 +603,10 @@ def init(self, boxes, style=None, **options):
587603
self.boxes, BoxElementMixin
588604
), f"{type(self.boxes)},{self.boxes}"
589605

606+
@property
607+
def is_multiline(self) -> bool:
608+
return self.boxes.is_multiline
609+
590610

591611
class SubscriptBox(BoxExpression):
592612
"""
@@ -768,6 +788,10 @@ def eval_tagbox(self, expr, form: Symbol, evaluation: Evaluation):
768788
assert isinstance(expr, BoxElementMixin), f"{expr}"
769789
return TagBox(expr, form, **options)
770790

791+
@property
792+
def is_multiline(self) -> bool:
793+
return self.boxes.is_multiline
794+
771795

772796
class TemplateBox(BoxExpression):
773797
"""

mathics/core/atoms/strings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def is_literal(self) -> bool:
9393
"""
9494
return True
9595

96+
@property
97+
def is_multiline(self) -> bool:
98+
return "\n" in self.value
99+
96100
def sameQ(self, rhs) -> bool:
97101
"""Mathics SameQ"""
98102
return isinstance(rhs, String) and self.value == rhs.value

mathics/core/element.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ class BoxElementMixin(ImmutableValueMixin):
407407
elements
408408
"""
409409

410+
@property
411+
def is_multiline(self) -> bool:
412+
return True
413+
410414
def boxes_to_format(self, format: str, **options) -> str:
411415
from mathics.core.formatter import boxes_to_format
412416

test/format/test_makeboxes.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import os
3-
from test.helper import check_evaluation
3+
from test.helper import check_evaluation, session
44

55
import pytest
66
import yaml
@@ -478,3 +478,64 @@ def test_makeboxes_custom2(str_expr, str_expected, msg):
478478
to_python_expected=False,
479479
failure_message=msg,
480480
)
481+
482+
483+
@pytest.mark.parametrize(
484+
["expr", "expect"],
485+
(
486+
(
487+
'"Hola"',
488+
False,
489+
),
490+
(
491+
'"Hola\nqué tal?"',
492+
True,
493+
),
494+
(
495+
"a/b//MakeBoxes",
496+
True,
497+
),
498+
(
499+
"Sqrt[a]//MakeBoxes",
500+
True,
501+
),
502+
(
503+
"a + b * c//MakeBoxes",
504+
False,
505+
),
506+
(
507+
"a + b / c//MakeBoxes",
508+
True,
509+
),
510+
(
511+
"a + b * c // InputForm//MakeBoxes",
512+
False,
513+
),
514+
(
515+
"a + b / c //InputForm//MakeBoxes",
516+
False,
517+
),
518+
(
519+
"a + b * c // OutputForm//MakeBoxes",
520+
False,
521+
),
522+
(
523+
"a + b / c // OutputForm//MakeBoxes",
524+
False,
525+
),
526+
(
527+
"a + b * c // FullForm//MakeBoxes",
528+
False,
529+
),
530+
(
531+
"a + b / c // FullForm//MakeBoxes",
532+
False,
533+
),
534+
),
535+
)
536+
def test_multiline(expr, expect):
537+
boxexpr = session.evaluate(expr)
538+
print(expr, "->", boxexpr, (expect))
539+
assert (
540+
boxexpr.is_multiline == expect
541+
), f"{boxexpr} must {'not ' if not expect else ''}be multiline. Got ({boxexpr.is_multiline})"

0 commit comments

Comments
 (0)