Repository: sympy/sympy

Issue:
pretty printing expint, polylog etc with opportunistic subscripts
Currently, we have:
```
>>> init_printing()
>>> expint(3,z)     # I look very nice!
E₃(z)

>>> expint(s, z)    # I could look nicer!
expint(s, z)

>>> expint(cos(s - 1)/17, z)    # but leave me be
      ⎛cos(s - 1)   ⎞
expint⎜──────────, z⎟
      ⎝    17       ⎠
```
`polylog` will behave the same after #25311.  Both use
``` 
       if e.args[0].is_Integer and self._use_unicode:
```

Perhaps one could use a helper function based on the list of things which can be subscripted:
```
from sympy.printing.pretty.pretty_symbology import sub

{'a': 'ₐ',
 'e': 'ₑ',
 'i': 'ᵢ',
 'o': 'ₒ',
 'r': 'ᵣ',
 'u': 'ᵤ',
 'v': 'ᵥ',
 'x': 'ₓ',
 'h': 'ₕ',
 'k': 'ₖ',
 'l': 'ₗ',
 'm': 'ₘ',
 'n': 'ₙ',
 'p': 'ₚ',
 's': 'ₛ',
 't': 'ₜ',
 'beta': 'ᵦ',
 'gamma': 'ᵧ',
 'rho': 'ᵨ',
 'phi': 'ᵩ',
 'chi': 'ᵪ',
 '0': '₀',
 '1': '₁',
 '2': '₂',
 '3': '₃',
 '4': '₄',
 '5': '₅',
 '6': '₆',
 '7': '₇',
 '8': '₈',
 '9': '₉',
 '+': '₊',
 '-': '₋',
 '=': '₌',
 '(': '₍',
 ')': '₎'}
```

Maybe there already is such a helper function?  If not, I suggest writing an `opportunistic_subscripter` or some such helper function.

Bessel and Hankel could also potentially benefit from this printing.

Discussion:

Patch:
diff --git a/.mailmap b/.mailmap
index f2e16fd408..2f824af324 100644
--- a/.mailmap
+++ b/.mailmap
@@ -393,6 +393,7 @@ Bharath M R <catchmrbharath@gmail.com>
 Bhaskar Gupta <guptabhanu1999@gmail.com>
 Bhaskar Joshi <bhaskar.joshi@research.iiit.ac.in> BhaskarJoshi-01 <bhaskar.joshi@research.iiit.ac.in>
 Bhautik Mavani <mavanibhautik@gmail.com>
+Bhavik Sachdev <b.sachdev1904@gmail.com> Bhavik Sachdev <69461338+bsach64@users.noreply.github.com>
 Bhavya Srivastava <bhavya17037@iiitd.ac.in>
 Bilal Ahmed <b.ahmed0918@gmail.com>
 Bilal Akhtar <bilalakhtar@ubuntu.com> <bilalakhtar96@yahoo.com>
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/pretty.py
index 4ced826b2c..75f49e4d9c 100644
--- a/sympy/printing/pretty/pretty.py
+++ b/sympy/printing/pretty/pretty.py
@@ -20,7 +20,7 @@
 from sympy.printing.pretty.stringpict import prettyForm, stringPict
 from sympy.printing.pretty.pretty_symbology import hobj, vobj, xobj, \
     xsym, pretty_symbol, pretty_atom, pretty_use_unicode, greek_unicode, U, \
-    pretty_try_use_unicode,  annotated
+    pretty_try_use_unicode, annotated, is_subscriptable_in_unicode
 
 # rename for usage from outside
 pprint_use_unicode = pretty_use_unicode
@@ -1664,8 +1664,9 @@ def _print_GeometryEntity(self, expr):
         return self.emptyPrinter(expr)
 
     def _print_polylog(self, e):
-        if e.args[0].is_Integer and self._use_unicode:
-            return self._print_Function(Function('Li_%s' % e.args[0])(e.args[1]))
+        subscript = self._print(e.args[0])
+        if self._use_unicode and is_subscriptable_in_unicode(subscript):
+            return self._print_Function(Function('Li_%s' % subscript)(e.args[1]))
         return self._print_Function(e)
 
     def _print_lerchphi(self, e):
@@ -1811,8 +1812,9 @@ def _print_DiracDelta(self, e):
             return self._print_Function(e)
 
     def _print_expint(self, e):
-        if e.args[0].is_Integer and self._use_unicode:
-            return self._print_Function(Function('E_%s' % e.args[0])(e.args[1]))
+        subscript = self._print(e.args[0])
+        if self._use_unicode and is_subscriptable_in_unicode(subscript):
+            return self._print_Function(Function('E_%s' % subscript)(e.args[1]))
         return self._print_Function(e)
 
     def _print_Chi(self, e):
diff --git a/sympy/printing/pretty/pretty_symbology.py b/sympy/printing/pretty/pretty_symbology.py
index b5b832ea5c..9b6b92bce7 100644
--- a/sympy/printing/pretty/pretty_symbology.py
+++ b/sympy/printing/pretty/pretty_symbology.py
@@ -641,3 +641,25 @@ def line_width(line):
     separate symbols and thus should not be counted
     """
     return len(line.translate(_remove_combining))
+
+
+def is_subscriptable_in_unicode(subscript):
+    """
+    Checks whether a string is subscriptable in unicode or not.
+
+    Parameters
+    ==========
+
+    subscript: the string which needs to be checked
+
+    Examples
+    ========
+
+    >>> from sympy.printing.pretty.pretty_symbology import is_subscriptable_in_unicode
+    >>> is_subscriptable_in_unicode('abc')
+    False
+    >>> is_subscriptable_in_unicode('123')
+    True
+
+    """
+    return all(character in sub for character in subscript)


Test patch:
diff --git a/sympy/printing/pretty/tests/test_pretty.py b/sympy/printing/pretty/tests/test_pretty.py
index 2907551dfb..5e7b53a1f5 100644
--- a/sympy/printing/pretty/tests/test_pretty.py
+++ b/sympy/printing/pretty/tests/test_pretty.py
@@ -80,7 +80,6 @@
 
 from sympy.vector import CoordSys3D, Gradient, Curl, Divergence, Dot, Cross, Laplacian
 
-from sympy.testing.pytest import XFAIL
 
 
 import sympy as sym
@@ -7508,7 +7507,7 @@ def test_print_polylog():
     assert upretty(polylog(2, 3)) == uresult
 
 
-@XFAIL  # Issue #25312
+# Issue #25312
 def test_print_expint_polylog_symbolic_order():
     s, z = symbols("s, z")
     uresult = 'Liₛ(z)'