Skip to content

Commit

Permalink
Add split_words macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver committed Jul 20, 2022
1 parent d8b7db3 commit 4193d63
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Resources/views/macros/split_words.tex.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{# Macro to split long words #}
{%- macro split_words(text, cutoff) -%}
{%- set cutoff = cutoff|default(20) -%}
{%- set output = text|latex_escape_all -%}
{%- set splittedOutput = output|split(' ') %}
{%- if splittedOutput|length == 1 -%}
\seqsplit{ {{- output|raw -}} }
{%- else -%}
{%- for splittedPart in splittedOutput -%}
{%- set splittedDash = splittedPart|split('-') -%}
{%- if splittedDash|length == 1 and splittedPart|length >= cutoff-%}
\seqsplit{ {{- splittedPart|raw -}} }
{%- elseif splittedDash|length > 1 -%}
{%- for splittedDashPart in splittedDash -%}
{%- if splittedDashPart|length >= cutoff -%}
\seqsplit{ {{- splittedDashPart|raw -}} }
{%- else -%}
{{- splittedDashPart|raw -}}
{%- endif -%}
{%- if not loop.last -%}{{- '-' -}}{%- endif -%}
{%- endfor -%}
{%- else -%}
{{- splittedPart|raw -}}
{%- endif -%}
{%- if not loop.last %} {% endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}

0 comments on commit 4193d63

Please sign in to comment.