0

When I try to put non-breaking space before citations, Latex does not show the symbol tilde (~) before the citations in rendered pdf.

Here is what I would like to see: According to xx (2013)~[refID]

According to xx (2013)~\cite{xx}
According to xx (2013)\nobreakspace\cite{xx}

However, what I get after using the codes above: According to xx (2013) [refID]

Minimal Working Example:

\documentclass{article}
\begin{filecontents}{\jobname.bib}
  @book{key,
        author = {Author, A.},
        year = {2001},
        title = {Title},
        publisher = {Publisher},
       }
\end{filecontents}

\begin{document}

According to xx\textasciitilde{}\cite{key}, ...

\bibliographystyle{plain} \bibliography{\jobname}

\end{document}

The MWE above produces the following output: enter image description here

The problem is the space after the tilde. How can I remove that?

bbasaran
  • 115
  • Maybe this is an answer to your question: https://tex.stackexchange.com/a/9365/140456 or the other ones in the same question. Maybe the way to go is to change the way your citations are displayed, but without a (MWE)[https://tex.meta.stackexchange.com/questions/4407/how-to-write-a-mweb-minimal-working-example-with-bibliography] it is impossible to help – Luis Turcio Jul 12 '21 at 16:34
  • ~ in LaTeX-syntax denotes a non-breaking-space: a~b means to place a<horizontal space>b into the .pdf-output-file so that a linebreak will not occur between a and b but a<horizontal space>b will always be on the same line. If you want a tilde, use the control sequence \textasciitilde. – Ulrich Diez Jul 12 '21 at 16:37
  • a non breaking space renders as a space just as &nbsp; renders as a space in HTML. It would look very odd to have a ~ in the typeset result. – David Carlisle Jul 12 '21 at 16:44
  • Thank you for the answers. Using \textasciitilde leaves an unwanted space after: https://pasteboard.co/KaR2add.png – bbasaran Jul 12 '21 at 16:51
  • @LuisTurcio I have just edited my post for MWE. Thanks! – bbasaran Jul 12 '21 at 17:03
  • Are you sure you want a tilde printed there? Given that ~ means a non-breaking space in LaTeX, I'm wondering whether you've misinterpreted some instructions for how to write citations. – Don Hosek Jul 12 '21 at 18:21
  • Not me but my professor wants to see that tilde printed there :) – bbasaran Jul 12 '21 at 18:22

1 Answers1

3

I cannot reproduce your picture. The picture generated at overleaf (via LuaLaTeX) is as follows: enter image description here

Below is what I tried using my own TeX Live 2021:

\documentclass{article}
\usepackage{textcomp}
\begin{filecontents}{\jobname.bib}
  @book{key,
        author = {Author, A.},
        year = {2001},
        title = {Title},
        publisher = {Publisher},
       }
\end{filecontents}

\begin{document}

According to xx\textasciitilde{ }\cite{key}, ...

According to xx\textasciitilde{}\cite{key}, ...

According to xx\textasciitilde\cite{key}, ...

According to xx\texttildelow\cite{key}, ...

According to xx\verb+~+\cite{key}, ...

According to xx$\sim$\cite{key}, ...

\bibliographystyle{plain} \bibliography{\jobname} \end{document}

enter image description here

citsahcots
  • 7,992
  • Actually your last example is what I exactly want. However, when I try According to xx$\sim$\cite{key}, it leaves a space after the tilde. – bbasaran Jul 12 '21 at 17:42
  • Then, you might want to reinstall your TeX distribution or upgrade to the latest version. – citsahcots Jul 12 '21 at 17:50
  • I am using Overleaf. I guess it is already the latest version. I could not understand what the problem is. – bbasaran Jul 12 '21 at 17:52
  • I updated my answer, showing the picture generated at overleaf using your MWE. – citsahcots Jul 12 '21 at 18:04
  • It is weird, because I try the same, but doesn't produce the same output. I am using toptesi document class. Maybe this is the problem. – bbasaran Jul 12 '21 at 18:25
  • 1
    Your MWE uses article, doesn't it? – citsahcots Jul 12 '21 at 18:32
  • Yes, but I wouldn't use toptesi here, since it is a specific packet and many people here wouldn't have it. – bbasaran Jul 12 '21 at 18:33
  • I tried toptesi at overleaf, still no extra space. – citsahcots Jul 12 '21 at 18:34
  • I have just tried now in a different part of the text and it did not leave extra space. Maybe it is because of two-sided justification. – bbasaran Jul 12 '21 at 18:50
  • So, your example is not really an MWE. It's hard to help with a moving target. – citsahcots Jul 12 '21 at 18:52
  • You are right, I will edit this. I thought that it would be better to make it as simple as possible. Anyway, your answer helped me a lot. It should be related to the justification. Thank you! – bbasaran Jul 12 '21 at 18:58