[simplex] Fix display of variables like x_12 in latex.

This commit is contained in:
Mikaël Capelle 2019-11-01 18:41:52 +01:00
parent 349caaff6b
commit e42e97064a

View File

@ -110,6 +110,18 @@ class simplex_dictionary:
return super().__setattr__(key, value)
def name_latex(self, name):
""" Convert the given variable name. """
name = str(name)
s = name.split('_')
# We only handle special case:
if len(s) == 1 or len(s) > 2:
return name
return s[0] + '_{' + s[1] + '}'
def value_latex(self, value):
if value.denominator == 1:
return str(value)
@ -125,10 +137,10 @@ class simplex_dictionary:
"""
d = (r'\begin{{array}}{{r||{}}}'.format(
'r|' * (1 + len(self.B)))
+ r' & b & ' + ' & '.join(str(v) for v in self.N) + r'\\\hline '
+ r' & b & ' + ' & '.join(self.name_latex(v) for v in self.N) + r'\\\hline '
+ r'\\'.join(
'{} & {} &'.format(
b,
self.name_latex(b),
self.value_latex(self.b[b])
)
+ ' & '.join(self.value_latex(-self.a[b][n]) for n in self.N)