I want to create below multiline document ( String ). I maintained one array in which I am pushing each line, but \ is getting replace automatically.
How can I create a string with single backslash.
\begin{document}
\begin{figure}[p]
\begin{tikzpicture}[x=0.2cm,y=0.6cm]
%define lines
\draw[gray, ultra thin] (0,0) --(30,0);
\node[label={[rotate=0]right: \makecell \textbf{Problem Statement}}] at (30,0) {};
\end{tikzpicture}
\end{figure}
\end{document}
If you are asking about multiline strings, if I don’t get you wrong, you can use here documents:
1. With tabs or spaces before each line:
puts <<-'EOF'
\hello world\
EOF
Output:
\hello world\
2. Without tabs or spaces before each line with squiggly heredoc:
puts <<~'EOF'
\hello world\
EOF
Output:
\hello world\
3. Using method chaining inside here docs:
puts <<~'EOF'.chars.*('-')
\hello world\
EOF
Output:
\-h-e-l-l-o- -w-o-r-l-d-\-
4. String interpolation:
puts <<EOF.chars.*('-') # or you can use double quotes: "EOF"...
\hello world\
#{50 + 50}
EOF
Output:
-h-e-l-l-o- -w-o-r-l-d- -1-0-0-
So, here docs can be very helpful. Note that you can use anything in place of EOF, but you need to close it. We used - before EOF that will prevent syntax error if the closing EOF begins with a space or a tab.
This is a very cool and handy feature that you can experiment with. Hopefully I have provided the right answer.
1 Like
Thanks for your reply.
For multiline string above syntax is correct and helpful.