[Tex/LaTex] Alternative to textit in LaTeX

italic

I have one text that need to be italicized.

   \textit{some text2 ~\\ some text2}

But i found ~\\ converted to \newline\. Is there any alternative to \textit? Is there any alternative to \it?

Best Answer

I assume your intent was to get a backslash, instead of a \newline which is what \\ is. In that case you can use \textbackslash with either the macro \textit{...}, or the font switch {\itshape ...} as in the first two lines below:

enter image description here

The third line above was produced with \emph{...} and yields identical results (in this case).

However, you should carefully consider why you are doing this. Do you want an italic font, or are you trying to emphasize some words? In most cases one is trying to emphasize some words in which case \emph{...} should be used. Note the differences in the following where we have nested uses of \textit{...}, {\itshape ...}, and \emph{...}:

enter image description here

Notes:

  • The { and } when using the switch \itshape is so that the italics font switch is only on during within a scope.

Code:

\documentclass{article}

\begin{document}

    \textit{some text2 ~\textbackslash~ some text2}
    
    {\itshape some text2 ~\textbackslash~ some text2} 
    
    \emph{some text2 ~\textbackslash~ some text2} 


    \medskip

    \textit{textit text  containing \textit{textit text}}
    
    {\itshape itshape text  containing {\itshape itshape text}}
    
    \emph{emphasized text containing \emph{emphasized text}} 

\end{document}