7

\^^,\^\^,\^ \^ all give error. \verb|^^| works, but if put inside \begin{leftbubbles} and \end{leftbubbles} from this answer How to make every line in a bubble like chat conversations? it gives error

! Missing } inserted.
<inserted text> 
                }

The same is true for rightbubbles. As you might have guessed, the ^^ are the emoji ^^

Why is ^^ compiled as M, and how to prevent this?

Ooker
  • 1,450
  • 1
  • 12
  • 26

1 Answers1

7

When you type ^^ (under normal category code setting, that is, when ^ has category code 7), TeX looks for the next character, say it has ASCII code x (less than 128) and substitutes the whole construction with the character having ASCII code x − 64 or x + 64, depending on which one is in the range 0–127.

Exception: if the following character is among 0123456789abcdef, TeX will look for a further character and, if again among those, it will substitute the four characters with the one having the ASCII code as specified by interpreting the two characters as hexadecimal digits.

It follows that typing ^^ for getting two carets is not possible. Also \verb doesn't work in argument to other commands and, unfortunately, the contents of a bubblesright environment must be absorbed as an argument to a macro.

Solution: define a specific command for that emoticon.

I suggest to add the following just before \ExplSyntaxOff:

\NewDocumentCommand{\ei}{m}{ \texttt { \tl_to_str:n { #1 } } }
\NewDocumentCommand{\eihh}{}{ \texttt { \tl_to_str:N ^ \tl_to_str:N ^ } }

and then you can type

\begin{rightbubbles}
Here \ei{;-)}

What \eihh

Another \ei{:-D}
\end{rightbubbles}

enter image description here

Alternative trickery.

Add, before \ExplSyntaxOff

\NewDocumentCommand{\ei}{m}{ \texttt { \tl_to_str:n { #1 } } }
\char_set_active_eq:nN { `^ } \c_math_superscript_token
\AtBeginDocument
 {
  \char_set_mathcode:nn { `^ } { "8000 }
  \char_set_catcode_other:n { `^ }
 }

Then the input

\begin{rightbubbles}
Here \ei{;-)}

What \ei{^^}

Another \ei{:-D}
\end{rightbubbles}

will produce the same output as before.

egreg
  • 1,121,712
  • in this context, using a specific command for emojis particularly might be wise, but in general I think it's simpler to use \texttt{\string^\string^}, isn't it? And even in this context, why should a specific command be needed over the quick hack? – Ooker Dec 11 '17 at 14:23
  • @Ooker I added another trick, changing the category code of ^ – egreg Dec 11 '17 at 14:24
  • 4
    @Ooker A specific command can be changed in the preamble; tricky input must be searched for every occurrence. – egreg Dec 11 '17 at 14:26
  • Why not just use 5E, the hex code for ^? Second, I think you mean "three characters" not "four characters" in "[...]it will substitute the four characters with the one having the ASCII code[...]" – Yakk Dec 11 '17 at 18:44
  • @Yakk Two carets and two hexadecimal digits – egreg Dec 11 '17 at 19:07
  • But what do you think about other options (\texttt or hex code)? – Ooker Dec 12 '17 at 01:35
  • 1
    @Ooker I am defining \eihh exactly as \textt{\string^\string\^} – egreg Dec 12 '17 at 07:02