Text Formattingwhy don't I get a linebreak?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
nirious
Posts: 5
Joined: Thu Dec 24, 2020 6:04 pm

why don't I get a linebreak?

Post by nirious »

I'm trying to line break an xpath, and thought adding a linebreak after each slash would do the job.
But for some reason it doesn't.

/{\allowbreak}n1:BR-CompanyDetailsResponse[1]/{\allowbreak}bacdo:Documents[1]/{\allowbreak}bacdo:Document[1]/{\allowbreak}bacci:CompanyItem[1]/{\allowbreak}bbc:CompanyItemExplanatoryLabel[1] \\/{\allowbreak}n1:BR-CompanyDetailsResponse[1]/{\allowbreak}bacpa:Particulars[1]/{\allowbreak}bacpa:Particular[1]/{\allowbreak}bacci:CompanyItem[1]/{\allowbreak}bbc:CompanyItemExplanatoryLabel[1]

result see in attachment.
Attachments
pdf result
pdf result
allowbreak doesn't work.png (11.41 KiB) Viewed 7983 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

nirious
Posts: 5
Joined: Thu Dec 24, 2020 6:04 pm

why don't I get a linebreak?

Post by nirious »

Can somebody please test this piece of code, I have extremely simplified my document so I don't have interference from other packages.

Why does it complain about an overfull hbox when I clearly tell it , it can cut after the slash.

I am missing some knowledge here.
why would someone want to loose text instead of wrapping around to the next line???
I don't understand this behavior at all.

Even this web editor wrap the text to the next line. But for some reason Latex can't/won't??

I can't put a hyphen as the path would become invalid, it needs to be 1 line and when not possible on one line, then continue on the next line.
why is this so hard to obtain?

\documentclass{article}


%allow to change pageborders
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}

\begin{document}

abc

/n1:BR-CompanyDetailsResponse[1]/bacco:Company[1]/bacad:RegisterffffffffedOffice[1]/\allowbreak/bbc:AddressLine1[1]

/n1:BR-CompanyDetailsResponse[1]/bacco:Company[1]/bacad:RegisteredOffffffffffffffffffffffffffffffffice[1]/\allowbreak/bbc:AddressLine1[2]

\end{document}
nirious
Posts: 5
Joined: Thu Dec 24, 2020 6:04 pm

why don't I get a linebreak?

Post by nirious »

I also tried \linebreak[4]
0 to3 does nothing
4 and 5 wrap the remainder to the next line, but they still also wrap the line when I shorten the string so it easily fits on one line.

The latex tex file is code generated so if really necessary I will calculate myself the length and put a \\ when appropriate but that solution would just be ridiculous.
nirious
Posts: 5
Joined: Thu Dec 24, 2020 6:04 pm

why don't I get a linebreak?

Post by nirious »

\- works as expected , except that I now have a - at the end of my line so they text can no longer be copy pasted as it has become invalid because of the -.


/n1:BR-CompanyDetailsResponse[1]/bacco:Company[1]/bacadoooooooooooooooooooooooooooooooo:jkk[1]\-/bbc:AddressLine1[2]
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

why don't I get a linebreak?

Post by Ijon Tichy »

\allowbreak is only \penalty 0, which is "allow break without extra costs" only. But there are other costs, because the line would be underfull in justified text. So even \linebreak[3] wouldn't be enough. \linebreak (that is same like \linebreak[4] would be enough, but result in an Underfull \hbox (badness 10000) in paragraph at lines 20--21 warning, because of the not justifiable text. Best would be so print such text ragged, e.g.

Code: Select all

\documentclass{article}

%allow to change pageborders
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
showframe% show the areas of the page for debugging
}

\begin{document}

abc

/n1:BR-CompanyDetailsResponse[1]/bacco:Company[1]/bacad:RegisterffffffffedOffice[1]/\allowbreak/bbc:AddressLine1[1]

\begin{flushleft}
  /n1:BR-CompanyDetailsResponse[1]/bacco:Company[1]/bacad:RegisteredOffffffffffffffffffffffffffffffffice[1]/\allowbreak/bbc:AddressLine1[2]
\end{flushleft}

\end{document}
Alternatively you could use \hfil\allowbreak instead of \allowbreak. But if you'd use this more than once in a line, there would be extra space inside the line.

BTW: Please don't use tag/button LaTex for several lines of code. Use the Code tag/button instead.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
nirious
Posts: 5
Joined: Thu Dec 24, 2020 6:04 pm

why don't I get a linebreak?

Post by nirious »

Thank you Ijon Tichy.
Flushleft + allowbreak was exactly the behavior I was after.


Can you provide me with a link to where I can find more info about this penalty system, as that is the missing knowledge that would have saved me some headaches.

or will it give me some headaches ? :)
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

why don't I get a linebreak?

Post by Ijon Tichy »

The paragraph breaking algorithm and the penalties and demerits are described in, e.g. TeX by Topic and the original manual: The TeX book.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply