Repository: Qiskit/qiskit

Issue:
Param display with pi's in mpl drawer inconsistent due to latex_to_text
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**: master
- **Python version**: 3.8
- **Operating system**: Ubuntu 18.04

### What is the current behavior?

The return from the latex_to_text call when the text comes from params that went through pi_check and contain pi is odd. Here are the ascii/unicode values from the return from the call with `text = $-$$\pi$/2, $-$$\pi$/2, $-$$\pi$/2`

`45 10 32 32 32 32 960 47 50 44 45 10 960 47 50 44 32 45 10 32 32 32 32 960 47 50`

Note the 10s (linefeed) and 32s (spaces). These seem to be arbitrarily thrown into the string and are somewhat random. No idea why. This affects the text width calc since this adds width. Note the 3rd gate below.

In addition the math mode minus sign is about twice the width of the hyphen that is used in pi_check, and is about the same width as the + sign. So replacing the hyphen with a + for the width calc will help as well.

Finally, the character that replaces non-ascii chars such as pi is a bit too small. Hence the tight spacing on the 2nd and 4th gates below.
![image](https://user-images.githubusercontent.com/16268251/89082334-8ae83f00-d342-11ea-8ebd-65adfa777831.png)

### Steps to reproduce the problem

```
from qiskit import QuantumCircuit
from numpy import pi

qc = QuantumCircuit(1)
qc.u3(-3*pi/2, -3*pi/2, -3*pi/2, 0)
qc.u3(3*pi/2, 3*pi/2, 3*pi/2, 0)
qc.u3(-pi/2, -pi/2, -pi/2, 0)
qc.u3(pi/2, pi/2, pi/2, 0)
qc.draw('mpl', filename='param_latex.png')
```

### What is the expected behavior?



### Suggested solutions

The obvious thing to do is to remove the 10s and 32s, replace the hyphen with a +, and make the default char larger. Note that the 32s always follow a 10, so if we remove `10 32 32 32 32` first and then any additional 10s, it should not affect other text. Of course, since we don't know why this stuff is there, this could change in a future release of latex_to_text, but this shouldn't do any serious harm in that case. Doing this produces,
![image](https://user-images.githubusercontent.com/16268251/89083058-a81e0d00-d344-11ea-83ea-896734c170b1.png)




Discussion:

Resolving patch:
diff --git a/qiskit/visualization/matplotlib.py b/qiskit/visualization/matplotlib.py
--- a/qiskit/visualization/matplotlib.py
+++ b/qiskit/visualization/matplotlib.py
@@ -258,7 +258,7 @@ def ast(self):
         return self._ast
 
     # This computes the width of a string in the default font
-    def _get_text_width(self, text, fontsize):
+    def _get_text_width(self, text, fontsize, param=False):
         if not text:
             return 0.0
 
@@ -273,7 +273,8 @@ def _get_text_width(self, text, fontsize):
                 math_mode_text = math_mode_match.group(1)
                 num_underscores = math_mode_text.count('_')
                 num_carets = math_mode_text.count('^')
-            text = LatexNodes2Text().latex_to_text(text)
+            text = LatexNodes2Text().latex_to_text(text.replace('$$', ''))
+
             # If there are subscripts or superscripts in mathtext string
             # we need to account for that spacing by manually removing
             # from text string for text length
@@ -282,14 +283,18 @@ def _get_text_width(self, text, fontsize):
             if num_carets:
                 text = text.replace('^', '', num_carets)
 
+            # This changes hyphen to + to match width of math mode minus sign.
+            if param:
+                text = text.replace('-', '+')
+
             f = 0 if fontsize == self._style.fs else 1
             sum_text = 0.0
             for c in text:
                 try:
                     sum_text += self._char_list[c][f]
                 except KeyError:
-                    # if non-ASCII char, use width of 'r', an average size
-                    sum_text += self._char_list['r'][f]
+                    # if non-ASCII char, use width of 'c', an average size
+                    sum_text += self._char_list['c'][f]
             return sum_text
 
     def param_parse(self, v):
@@ -354,7 +359,7 @@ def _multiqubit_gate(self, xy, fc=None, ec=None, gt=None, sc=None, text='', subt
 
         # added .21 is for qubit numbers on the left side
         text_width = self._get_text_width(text, self._style.fs) + .21
-        sub_width = self._get_text_width(subtext, self._style.sfs) + .21
+        sub_width = self._get_text_width(subtext, self._style.sfs, param=True) + .21
         wid = max((text_width, sub_width, WID))
 
         qubit_span = abs(ypos) - abs(ypos_max) + 1
@@ -389,7 +394,7 @@ def _gate(self, xy, fc=None, ec=None, gt=None, sc=None, text='', subtext=''):
         xpos, ypos = xy
 
         text_width = self._get_text_width(text, self._style.fs)
-        sub_width = self._get_text_width(subtext, self._style.sfs)
+        sub_width = self._get_text_width(subtext, self._style.sfs, param=True)
         wid = max((text_width, sub_width, WID))
 
         box = patches.Rectangle(xy=(xpos - 0.5 * wid, ypos - 0.5 * HIG),
@@ -764,7 +769,8 @@ def _draw_ops(self, verbose=False):
                     if op.name == 'initialize':
                         param = '[%s]' % param
                     param = "${}$".format(param)
-                    param_width = self._get_text_width(param, fontsize=self._style.sfs) + 0.08
+                    param_width = self._get_text_width(param, fontsize=self._style.sfs,
+                                                       param=True) + 0.08
                 else:
                     param_width = 0.0
 


Test patch:
diff --git a/test/ipynb/mpl/references/cswap_rzz.png b/test/ipynb/mpl/references/cswap_rzz.png
Binary files a/test/ipynb/mpl/references/cswap_rzz.png and b/test/ipynb/mpl/references/cswap_rzz.png differ
diff --git a/test/ipynb/mpl/references/partial_layout.png b/test/ipynb/mpl/references/partial_layout.png
Binary files a/test/ipynb/mpl/references/partial_layout.png and b/test/ipynb/mpl/references/partial_layout.png differ
diff --git a/test/ipynb/mpl/references/pi_in_param_expr.png b/test/ipynb/mpl/references/pi_in_param_expr.png
Binary files a/test/ipynb/mpl/references/pi_in_param_expr.png and b/test/ipynb/mpl/references/pi_in_param_expr.png differ
diff --git a/test/ipynb/mpl/references/r_gates.png b/test/ipynb/mpl/references/r_gates.png
Binary files a/test/ipynb/mpl/references/r_gates.png and b/test/ipynb/mpl/references/r_gates.png differ
diff --git a/test/ipynb/mpl/references/u_gates.png b/test/ipynb/mpl/references/u_gates.png
Binary files a/test/ipynb/mpl/references/u_gates.png and b/test/ipynb/mpl/references/u_gates.png differ