3

When using \urlstyle{same}, the url package will substitute a low 'faked' tilde, even if the lowtilde option is not specified:

\documentclass{article}

\usepackage{url} \urlstyle{same}

\begin{document}

Tilde: \textasciitilde

Not a tilde: \url{~}

\end{document}

Why does this happen, and is there a way to overrule this?

I am using the IEEEtran class, which forces the \urlstyle{same} option, and I am submitting to a journal, so I'd rather not load the hyperref package (which is suggested as a workaround elsewhere on this site) because that may not be allowed / be silently removed in editing.

oulenz
  • 167
  • 2
    Use \def\UrlTildeSpecial{\do\~{\hbox{\textasciitilde}}} but see Mico's answer also. – yannisl Jan 17 '24 at 04:03
  • 1
    simply \def\UrlTildeSpecial{} should be enough. But better is not to use OT1 encoding. As you mention copy&paste in a comment below: \usepackage[T1]{fontenc} resolves this and other copy&paste problems. – Ulrike Fischer Jan 17 '24 at 09:28
  • @yannisl Thanks! That works, but I just realised that there is a secondary issue, namely that with the default font, \textasciitilde produces a combining tilde rather than the ascii tilde. – oulenz Jan 17 '24 at 09:30
  • @UlrikeFischer Thank you! With \usepackage[T1]{fontenc}, ~ indeed copies correctly, even the lowered version. I still believe the url package is not behaving according to its own specifications, but my underlying problem is solved. What I don't understand is why with T1 encoding, the high and the lowered tilde suddenly copy as the same character (the ascii tilde), while with OT1 encoding they copy as two different (non-ascii!) characters. That runs entirely counter to the idea that OT1 has the smaller character set and is restricted to ascii. – oulenz Jan 17 '24 at 10:07
  • 1
    ot1 has only place for 128 characters but it has to provide text symbols which are not in ascii (like accents) and that can be quite challenging and leads to various problems (not only in copy&paste), e.g. it fakes the tilde with the tilde accent. Simply avoid the encoding. See also https://tex.stackexchange.com/a/675103/2388 – Ulrike Fischer Jan 17 '24 at 10:13

2 Answers2

2

Quoting from p. 382 of the Comprehensive LaTeX Symbol List [emphasis added]:

Note that \textasciitilde and \~{} produce raised, diacritic tildes. “Text” (i.e., vertically centered) tildes can be generated with either the math-mode \sim command ..., which produces a somewhat wide “∼”, or the textcomp package's \texttildelow, which produces a vertically centered “~” in most fonts but a baseline-oriented “~” in Computer Modern, txfonts, pxfonts, and various other fonts originating from the TEX world. If your goal is to typeset tildes in URLs or Unix filenames, your best bet is to use the url package ...

In short, what you call a "faked tilde" is, in fact, a vertically centered symbol which should be perfectly acceptable when it's used in text-mode settings, and especially when it's used in URL strings.

Mico
  • 506,678
  • Mico the OPs issue is with the url package that needs an update! I just went over it quickly handles different encodings but not TU. So the package is forcing the math-mode. See my comment at the question. – yannisl Jan 17 '24 at 04:12
  • @yannisl - I’m not sure I follow you. At present, I can’t see a good reason for preferring the diacritic-level symbol produced by \textasciitilde over a slightly lower-placed version of the same glyph if the symbol clearly is not intended to function as a diacritic mark. – Mico Jan 17 '24 at 05:13
  • The reason why this is not acceptable in my situation, is because when you go and copy the resulting url into an address bar, as one of my reviewers did, you don't get the correct address, and it's not at all obvious why. That's why I call it a 'faked' tilde, because it's not the same character. – oulenz Jan 17 '24 at 08:47
  • You haven't explained why this happens or what to do about it. The url documentation claims that "Normal treatment of the ~ character is to use the font’s \textasciitilde character", unless one specifies the lowtilde option, which I haven't. – oulenz Jan 17 '24 at 08:55
  • @oulenz - Please give an example of a real-world URL that contains a tilde. That would help me investigate further. – Mico Jan 17 '24 at 11:46
  • @Mico It's quite common in personal academic websites, e.g. https://www1.maths.leeds.ac.uk/~charles/statlog/index.html. But as suggested by UlrikeFischer in the comment thread to my question, the copying/pasting is solved with T1 encoding. I do think it's still an issue that the url package lowers the tilde even though the lowtilde option is not called, since it's inconsistent and goes against the package documentation. And if we want lowered tildes to be the default and high tildes the exception, then that should be properly implemented and documented in the url package. – oulenz Jan 17 '24 at 12:44
1

I guess that the problem is in the definition of \Url@OTnonTT, where \UrlTildeSpecial is used instead of \Url@force@Tilde.

The last command is \relax, unless lowtilde has been specified.

\documentclass{article}
\usepackage{url}

\makeatletter \def\Url@OTnonTT{\do&lt;{\langle}\do&gt;{\mathbin{\rangle}}\do _{_\penalty@m}\do|{\mid}\do{{\lbrace}\do}{\mathbin{\rbrace}}\do \{\mathbin{\backslash}}\Url@force@Tilde}% <--- it had \UrlTildeSpecial \makeatother

\urlstyle{same}

\begin{document}

Tilde: \textasciitilde

Not a tilde: \url{~}

\end{document}

enter image description here

egreg
  • 1,121,712