1

I have written a document with 200 references. (every round bracket (...) in my document is a collocation (here a combination of three words) which shouldn't get split. What I want is to have the structure: "(i j)" on only one line.

One possible solution to solve this problem is to use a global definition and then to use each time the link to this macro:

\documentclass[11pt]{article}
\usepackage[a4paper,left=3.2cm,right=3.2cm,top=2cm,bottom=4cm,bindingoffset=5mm]{geometry}

\newcommand{\nobreakword}[1]{\mbox{#1}}
\begin{document}
\begin{flushleft}

"Und wir haben die Liebe erkannt und geglaubt, die Gott zu uns hat. Gott ist Liebe, und wer in der Liebe bleibt, der bleibt in Gott und Gott in ihm" \nobreakword{(1. Johannes 4,16)}

"Der HERR ist mir erschienen von ferne: Ich habe dich je und je geliebt, darum habe ich dich zu mir gezogen aus lauter Güte." \nobreakword{(Jeremia 31,3)}

"Denn so hat Gott die Welt geliebt, dass er seinen eingeborenen Sohn gab, damit jeder, der an ihn glaubt, nicht verloren geht, sondern ewiges Leben hat.'' \nobreakword{(Joh. 3,16)}

\end{flushleft}
\end{document}

The sentence structure inside the round brackets should not be broken without declaring with \nobreakword{(...)} because this takes a lot of time. LaTex should recognize manually the collocation because of the round brackets (...) and dont split it.

I guess LaTex is not able to read pattern starting with "(" and ending with ")" and automatically recognize that this symbols (without writing a "\" command directly in the text) declares that the text including the round brackets have to be on the same line. Or is it possible?

  • Assuming you don't actually have underscores in the word(s) (not that it really matters), this should be as simple as \newcommand{\nobreakword}{\mbox} which makes \nobreakword act exactly like \mbox; or \newcommand{\nobreakword}[1]{\mbox{(#1)}} (which includes the brackets (..)). Then you'd use \nobreakword{...}. However, you may run into problems where (...different_text_inside_the_brackets...) run into the margin. For this \sloppy could help. – Werner Apr 1 '15 at 21:11
  • @Werner I think the first is needed, isn't it? So that you can say \nobreakword{"text" (whatever inside the brackets)}? Though I'm not sure I've understood 'combination' correctly.... – cfr Apr 2 '15 at 0:12
  • @Werner I've tried \newcommand{\nobreakword}{\mbox} \newcommand{\nobreakword}[1]{\mbox{(#1)}} \nobreakword{...} without luck. Actually the reference in the round brackets contains many different words which are separate with normal blank characters, but the whole reference including the round brackets can be placed on only one line. – laminin Apr 2 '15 at 16:47
  • It would help if you posted your attempt at \nobreakword. An \mbox will not break across lines, but it could wind up sticking out in odd or less desirable ways if its content is rather long. – A.Ellett Apr 2 '15 at 17:08
  • ...after you defined the macro, you need to use it. So you'll need ...sehr langer Text. \nobreakword{(Erster ...)} Dies ist ein... – Werner Apr 2 '15 at 18:50
2

If you only have the references inside brackets and nothing else fancy... not even nested, then you can make ( active and capture the contents between (...) to manage it:

enter image description here

\documentclass{article}

\newcommand{\nobreakword}[1]{\mbox{#1}}
\begin{document}

\raggedright

BEFORE\ldots

``Und wir haben die Liebe erkannt und geglaubt, die Gott zu uns hat. Gott ist Liebe, und wer in der Liebe bleibt, der bleibt in Gott und Gott in ihm'' (1.\ Johannes 4,16)

``Der HERR ist mir erschienen von ferne: Ich habe dich je und je geliebt, darum habe ich dich zu mir gezogen aus lauter Güte.'' (Jeremia 31,3)

``Denn so hat Gott die Welt geliebt, dass er seinen eingeborenen Sohn gab, damit jeder, der an ihn glaubt, nicht verloren geht, sondern ewiges Leben hat.'' (Joh.\ 3,16)

\let\oldlbrack( % Store old meaning of "("
\catcode`\(\active % Make "(" active
\def(#1){\nobreakword{\oldlbrack{}#1)}} % Define "(" to capture everything between (..) and ...
                                        % ... wrap it inside a \nobreakword.

AFTER\ldots

``Und wir haben die Liebe erkannt und geglaubt, die Gott zu uns hat. Gott ist Liebe, und wer in der Liebe bleibt, der bleibt in Gott und Gott in ihm'' (1.\ Johannes 4,16)

``Der HERR ist mir erschienen von ferne: Ich habe dich je und je geliebt, darum habe ich dich zu mir gezogen aus lauter Güte.'' (Jeremia 31,3)

``Denn so hat Gott die Welt geliebt, dass er seinen eingeborenen Sohn gab, damit jeder, der an ihn glaubt, nicht verloren geht, sondern ewiges Leben hat.'' (Joh.\ 3,16)

\end{document}

Here is a very short introduction to the above procedure: How does one make two characters active?


For future reference, if you have something that is really repetitive, consider wrapping it in a macro. It allows you to tap into that macro in the future and manipulate its contents rather than resorting to \catcode trickery.

  • You made my day! In the text I found two examples 1.) a very long sentence inside a round bracket which is too long for one line and 2.) a structure containing a URL: (nach Hebr 4,12; bibleserver.com/text/SLT/Hebr%C3%A4er4.12-15) Can I also manually say that these two cases are excluded from being active? – laminin Apr 2 '15 at 20:31
  • 1
    If you want to exclude certain ones from the now-active ( mechanism, you can use \oldlbrack ... ) in your text rather than ( ... ). \oldlbrack is a capture of ( before it was made active and changed. – Werner Apr 2 '15 at 20:35
1

If your reference is always going to be preceded by quoted material, you could do something along the following lines:

\documentclass{article}
\usepackage{lipsum}
\makeatletter
\newcommand\myquote{\my@quote}
\def\my@quote(#1)#2{``#2''~\mbox{(#1)}}
\makeatother
\begin{document}

\myquote(1. Johannes 4,16){Und wir haben die Liebe erkannt und geglaubt, die Gott zu uns hat. Gott ist Liebe, und wer in der Liebe bleibt, der bleibt in Gott und Gott in ihm} 

\end{document}

It's not necessary to put the source first, I could have defined this as

\def\my@quote#1(#2){``#1''~\mbox{(#2)}}

The ~ is in there so that the reference isn't isolated on a line by itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.