Removing Spaces In Totals Area Of Invoice Template

I am hoping this is possible: When editing the invoice document (via Design > Documents > Invoice), I see in the totals section at the bottom that all of these fields are there:

{{ __("subtotal") }}	{{o.display_subtotal}}
{{o.tax_name}}	{{o.tax_total}}
{{ __("shipping") }}	{{ o.display_shipping_cost }}
{% if o.coupon_code %}
{{ __("coupon") }}
{% endif %}	{% if o.coupon_code %} {{o.coupon_code}} {% endif %}
{% if o.raw.discount %}
{{ __("including_discount") }}
{% endif %}	{% if o.raw.discount %} {{o.discount}} {% endif %}
{% if o.raw.subtotal_discount %}
{{ __("order_discount") }}
{% endif %}	{% if o.raw.subtotal_discount %} {{o.subtotal_discount}} {% endif %}
{{ __("total") }}	{{o.total}}

Many times are are no tax, discount or coupon codes, so in the printed invoice it leaves an empty space where those fields would go. When it prints it often prints just the final total on a new page. So I am wondering if there's a way to have the invoice remove those empty spaces so it's condensed to single lines when there's no data for those fields to print?

Any ideas?

Any ideas?

Try to add conditions to all fields. E.g.

{% if o.display_subtotal %}
{{ __("subtotal") }}	{{o.display_subtotal}}
{% endif %}
{% if o.tax_total %}
{{o.tax_name}}	{{o.tax_total}}
{% endif %}
{% if o.display_shipping_cost %}
{{ __("shipping") }}	{{ o.display_shipping_cost }}
{% endif %}
{% if o.coupon_code %}
{{ __("coupon") }}	{{o.coupon_code}} 
{% endif %}
{% if o.raw.discount %}
{{ __("including_discount") }}
{% endif %}	
{% if o.raw.discount %} 
{{o.discount}}    {{ __("order_discount") }}
{% endif %}	
{% if o.raw.subtotal_discount %} 
{{o.subtotal_discount}} 
{% endif %}
{{ __("total") }}	{{o.total}}