Reputation: 1802
I have a string like that: line1\nline2\n\nline3
I want to show this string in PDF. I use Java, Freemarker and LaTeX.
I have Freemarker template like that: ${root.text}
, where root.text
is my string.
In PDF it looks like that:
line1 line2
line3
What I want to see:
line1
line2
line3
How can I receive this?
I tried to replace \n
with \newline
, but this doesn't work:
line1 ewlineline2
line3
Upvotes: 0
Views: 1059
Reputation: 1802
I've decided to create separate paragraphs for LaTeX with split
:
<#assign lines = root.text?split("\n") />
<#list lines as line>
${line} <#if line?has_next>\\</#if>
</#list>
This works as I expected.
Also, esaping rules can be added to CommonTemplateMarkupOutputModel#output
.
For example, \n
can be replaced with \\\\
.
Upvotes: 0
Reputation: 51521
This is most likely a conceptual problem with how LaTeX/TeX works. Text that is in a single “block” is treated as a paragraph. TeX determines the appropriate linebreaks itself. To separate paragraphs, you use more than one newlines (i. e. empty lines between).
It doesn't matter how many newlines there are, the meaning is “new paragraph”.
If you compile the string
line1
line2
line3
there will just be three paragraphs (likely indented, unless you changed that).
In order to get additional vertical space, you might try this input:
line1
line2
\vspace{\baselineskip}
line3
Sometimes what you want is an actual newline instruction, which is a double backslash (so, quadruple if escaped in a Java string representation):
line1\\
line2\\
\\
line3
I guess that you might want to strive to actually learn LaTeX (and maybe typesetting), though.
Upvotes: 2