1

It seems that LaTeX compiler randomly spaces out some of the words, somewhere in the text. Code is always the same, just it sometimes choses to randomly make a huge gap between two words. Please help! as shown on the first pic

and here is the code

  • Note: in one line I tried to type "~" instead of blank space, but no progress. Same huge gap.. – Markob15 Aug 20 '22 at 02:17
  • 2
    Welcome to tex,sx, The excessive space is the result of the bibliography being set justified, when the urls aren't able to break. Using \raggedright will set the spaces at their "normal" size; there are also some options provided by packages to allow (limited) breakpoints in the urls. – barbara beeton Aug 20 '22 at 03:19
  • 2
    Please post code, not screenshots. – Ingmar Aug 20 '22 at 03:22
  • @Ingmar Both code and screenshots. Screenshots can be nice exhibiting those aspects of a piece of TeX-output whose appearance one likes to be changed. – Ulrich Diez Aug 20 '22 at 03:26
  • @Markob15 In horizontal mode (the mode in which TeX creates paragraphs automatically) and in restricted horizontal mode (the mode in which creates a horizontal line of text but does not do linebreaking for you) noth ~ and ordinary space characters usually just "tell" TeX that there is a place where horizontal glue can be inserted for separating words. With ~ a linebreak may not occur but the width of the horizontal glue between words is not affected. – Ulrich Diez Aug 20 '22 at 03:30
  • @UlrichDiez; I meant screenshots of code … Sure, an illustration is always welcome. – Ingmar Aug 20 '22 at 06:38

2 Answers2

3

Here I don't see randomness in TeX's behavior.

TeX typesets the text of the paragraphs that form the items of the bibliography justified. The URL represents a very long last word that cannot be hyphenated and that does not fit into the remaining horizontal space of the line of text which TeX is constructing. So the URL goes on a line on its own, which results in the line above the URL containing not much text, so in order to maintain justification, the horizontal space between words of that line gets very large.

I suggest either using \raggedright/adjusting \rightskip or using the package xurl for typesetting the URLs. With that package you can configure breaking the URL across lines without a hyphenation-dash. The answers to the question forcing linebreaks in url might be of interest to you.
If you wish to do things by hand, you can probably insert in your TeX-code \discretionary{}{}{} between those characters of an URL where the URL may be broken across lines.

As you don't reveal your (La)TeX-code I cannot give detailed suggestions on how to modify it.

Ulrich Diez
  • 28,770
  • Thanks a lot! When I think about it, it totally makes sense. Here is a code snipet: \bibitem{GGabout}Osnovne informacije o programskom paketu GeoGebra: geogebra.org/about \bibitem{sajt}Veb sajt koji sadrži ceo materijal izložen u radu: alas.matf.bg.ac.rs\textasciitilde ml05184 – Markob15 Aug 25 '22 at 17:55
0

The screenshot you posted contains what you say are three instances of the "LaTeX compiler randomly spac[ing] out some of the words, somewhere in the text." I would go even farther and say that in addition to the entries numbered 12, 13, and 16, the following entries are also afflicted by excess amounts of interword whitespace: 14, 17, and 22. Moreover, entry 18 suffers from a massively overfull line.

However, contrary to your assertion, there is absolutely nothing random or unpredictable going on here. If you cast a casual glance at the seven entries in question, you should notice that they all feature a long URL string toward the end of the bibliographic entry. LaTeX simply doesn't know how to line-break these long strings. The next best LaTeX can do is to start inserting huge amounts of interword whitespace in a determined effort not to create underfull lines.

The fix? You need to provide a way for LaTeX to line-break URL strings. This may be achieved fairly easily. You should (a) load the xurl package and (b) encase all URL strings in \url directives. E.g.,

\url{https://wiki.geogebra.org/en/Scripting_Commands}

With this setup, LaTeX will be able to insert line breaks anywhere in a URL string.

If your TeX installation is quite old (say, older than about two years), the xurl package may not yet be installed. If \usepackage{xurl} throws an error message, you should replace it with \usepackage{hyphens,spaces]{url}.

Incidentally, it looks like you have diligently "escaped" all TeX-special characters -- mainly _ (underscore) -- that occur in URL strings. You'll need to remove those escape characters.

Mico
  • 506,678