3

I used the package embrac that the following question Upright parentheses in italic text let to.

However, If I define a simple environment, it will not work. See the example below. How can I fix this?

\documentclass{article}

\usepackage{embrac}

\begin{document}

\newcommand*{\TextA}{(\ldots) this is a citation from a famous author}
\newcommand*{\TextB}{\textup{(\ldots)} this is a citation from a famous author}

\textit{\TextA}\\
\textit{\TextB}\\
\TextA

\end{document}
  • 3
    \expandafter\textit\expandafter{\TextA}. embrac doesn't make \textit expand its argument – clemens Aug 10 '15 at 14:26
  • BTW: \newcommand doesn't define an environment. That would be \newenvironment. – clemens Aug 10 '15 at 14:27
  • Yes. You are right. It was a misspelling from my side. I just wanted a command to illustrate the behaviour. – cacamailg Aug 10 '15 at 14:42
  • @clemens is it difficult/break something if internally you make embrac expand textit or emph? – cacamailg Aug 10 '15 at 14:45
  • 1
    Quite easy, actually. In an expl3 programming catcode regime: \cs_generate_variant:Nn \embrac_textit:nn {no} (same for \emph and \textsl) – clemens Aug 10 '15 at 14:51
2

You need to expand \TextA before feeding it to \textit:

\expandafter\textit\expandafter{\TextA}

If you like you can redefine \textit in such a way that it expands its argument one time first:

\ExplSyntaxOn
\cs_generate_variant:Nn \embrac_textit:nn {no}

\RenewDocumentCommand \textit {sm}
  {
    \IfBooleanTF {#1}
      { \embrac_textit:no {*} {#2} }% using the new variant
      { \embrac_textit:no { } {#2} }% using the new variant
  }
\ExplSyntaxOff

(Correspondingly with \embrac_emph:nn for \emph and \embrac_textsl:nn for \textsl)

Note that this only expands the argument once. In \textit{x\TextA} \TextA still won't be expanded. You'd need an x-variant then (\edef-like expansion) but that might be dangerous… Maybe some \etextit for usage on own risk:

\ExplSyntaxOn
\cs_generate_variant:Nn \embrac_textit:nn {nx}

\NewDocumentCommand \etextit {sm}
  {
    \IfBooleanTF {#1}
      { \embrac_textit:nx {*} {#2} }
      { \embrac_textit:nx { } {#2} }
  }
\ExplSyntaxOff
  • This actually works. Maybe you can add it to your package as an option like expandfirst and also the second variant, with an alert to users. – cacamailg Aug 10 '15 at 15:10
  • Strangely it works with the mininal example, but it is not working with the full document that I am working on. Any ideas? – cacamailg Aug 10 '15 at 15:29
  • @cacamailg No? I don't know your document and not your use case – clemens Aug 10 '15 at 15:31
  • The preamble is to big to add it here. I will try to investigate what is happening. Thanks – cacamailg Aug 10 '15 at 15:38

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.