Repository: Qiskit/qiskit

Issue:
latex drawer produces empty output 
<!-- ⚠️ 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**:
- **Operating system**:

### What is the current behavior?


for a fairly large circuit, latex drawer outputs an empty box.

```python
qasm = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[20];
u3(1.60000000000000,0.0,0.0) q[0];
cx q[0],q[5];
u3(1.60000000000000,0.0,0.0) q[5];
cx q[0],q[5];
u3(1.60000000000000,0.0,0.0) q[5];
cx q[0],q[5];
u1(0.790000000000000) q[5];
cx q[0],q[5];
cx q[1],q[6];
cx q[6],q[1];
cx q[1],q[6];
cx q[0],q[1];
cx q[0],q[5];
u3(0.230000000000000,0.0,0.0) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[0],q[5];
u3(-0.790000000000000,0.0,0.0) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[0],q[5];
u3(-0.230000000000000,0.0,0.0) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[0],q[5];
u3(0.790000000000000,0.0,0.0) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[0],q[5];
u1(0.790000000000000) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[0],q[5];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[0],q[5];
u1(-0.790000000000000) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[0],q[1];
cx q[5],q[10];
cx q[6],q[10];
cx q[10],q[6];
cx q[6],q[10];
cx q[6],q[1];
cx q[1],q[6];
cx q[0],q[1];
cx q[0],q[5];
u3(-0.790000000000000,0.0,0.0) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[6],q[1];
u3(-0.790000000000000,0.0,0.0) q[1];
cx q[0],q[1];
cx q[0],q[5];
cx q[5],q[0];
cx q[0],q[5];
cx q[6],q[1];
cx q[0],q[1];
cx q[0],q[5];
u3(0.790000000000000,0.0,0.0) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[6],q[1];
u1(0.790000000000000) q[1];
cx q[0],q[1];
cx q[0],q[5];
u1(-0.790000000000000) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[6],q[1];
cx q[0],q[1];
cx q[0],q[5];
u1(-0.790000000000000) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[6],q[1];
cx q[0],q[1];
cx q[0],q[5];
u1(0.790000000000000) q[1];
cx q[5],q[0];
cx q[0],q[5];
cx q[6],q[1];
cx q[0],q[1];
u1(0.790000000000000) q[1];
cx q[6],q[1];
"""
circ = QuantumCircuit.from_qasm_str(qasm)
circ.draw(output='latex')


Discussion:
I'm having a hard time parsing the qasm in your example can you maybe paste it as a standalone file (or code snippet with the white space) so I can test that locally. However looking at your script I think you might just have a typo in there. `qasm = new_circ.qasm()` will overwrite that big qasm string with the qasm from whatever `new_circ` is (since I don't have the full script I don't know). If it's an empty circuit that would explain the empty output.
@mtreinish Code snippet updated. The original was a typo on my part.
Interesting, so I ran this with `latex_source` output and it does generate output. But when I rendered it with pdflatex manually it's on 2 pages not 1: [test.pdf](https://github.com/Qiskit/qiskit-terra/files/3096232/foo.pdf) so this is a bug in either our latex settings that's causing it to wrap on 2 pages or in our pdf->png conversion stage (including the png trimming) that's not getting the output. Either way this gives us a starting point to start fixing this.

Resolving patch:
diff --git a/qiskit/visualization/latex.py b/qiskit/visualization/latex.py
--- a/qiskit/visualization/latex.py
+++ b/qiskit/visualization/latex.py
@@ -222,6 +222,18 @@ def _get_image_depth(self):
         """
 
         max_column_widths = []
+        # Determine row spacing before image depth
+        for layer in self.ops:
+            for op in layer:
+                # useful information for determining row spacing
+                boxed_gates = ['u0', 'u1', 'u2', 'u3', 'x', 'y', 'z', 'h', 's',
+                               'sdg', 't', 'tdg', 'rx', 'ry', 'rz', 'ch', 'cy',
+                               'crz', 'cu3', 'id']
+                target_gates = ['cx', 'ccx']
+                if op.name in boxed_gates:
+                    self.has_box = True
+                if op.name in target_gates:
+                    self.has_target = True
 
         for layer in self.ops:
 


Test patch: