# How to define a new command for guillemets marks [duplicate]

Possible Duplicate:
babel shorthand "| doesn’t work in macros

I would like to define a new command for guillemets marks. I know how to obtain them in LaTeX and those I would like to use are produced by this code:

"<lorem ipsum dolor sit amet">


with italian option for the babel package (my complete code will follow below).

I tried to define my new command as

\newcommand{\guille}[1]{"<#1">}


but it doesn't work and it simply produces the same as

\textquotedbl\textless ... \textquotedbl\textgreater


Now, if I define

\newcommand{\newtextemdash}{---}


LaTeX correctly replaces --- with an em-dash. Why this replacement does not occur with "< and ">?

Finally, where can I find the rule such that --- must be replaced by \textemdash? And the one for "< and for ">?

\documentclass{minimal}
\usepackage[italian]{babel} % this activates "<...">
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\newcommand{\guille}[1]{"<#1">} % this does not work
\newcommand{\newtextemdash}{---} % this works
\begin{document}
Lorem ipsum dolor \newtextemdash{} sit amet \newtextemdash{} consectetuer adipiscing elit.
\guille{Lorem ipsum dolor si amet}
I would like to have this: "<Lorem ipsum dolor sit amet">
\end{document}


-
–  Qrrbrbirlbel Feb 1 at 20:36
For Italian there's no space problem, so <<testo>> works if the T1 encoding is in force. –  egreg Feb 1 at 20:36
The " shorthands are babel specific, whereas --- comes from (La)TeX itself. As for its definition, there’s the unanswered question What are the TeX definitions for the hyphen and dashes -, --, and ---?, which points to How does TeX's mechanism for sorting out quotation marks work?, where a apparently parallel case for quotation marks is explained. –  doncherry Feb 2 at 4:34
@doncherry Thank you very much! Before posting my questions I have looked for a solution a lot, even directly here on this site, unfortunately I didn't know what to search exactly (I didn't know technical terms such as "shorthands" or "LICR") and then I could not find the answers pointed out by Qrrbrbirlbel and you. I looked at the sources of babel, t1enc.def and others without understandig how to fix my problem. However, all the answers pointed out are useful for solving my doubts, thanks! –  Onner Irotsab Feb 2 at 10:13
@Qrrbrbirlbel I've seen you had posted an answer using \AtBeginDocumen{}, but I didn't succeed in reading your answer completely. Please, could you post it again? I've fixed my code for obtaining my purpose, anyway I'm interested in your solution. Of course, if it is not a problem! Thank you! –  Onner Irotsab Feb 2 at 13:50

## marked as duplicate by Qrrbrbirlbel, David Carlisle, Heiko Oberdiek, diabonas, cgniederFeb 1 at 22:03

You need to use the command form, or define your command after begin document once babel has set up the " shorthand:

\documentclass{minimal}
\usepackage[italian]{babel} % this activates "<...">
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\newcommand{\guille}[1]{\guillemotleft#1\guillemotright}
\newcommand{\newtextemdash}{---} % this works
\begin{document}
%\newcommand{\guille}[1]{"<#1">}

Lorem ipsum dolor \newtextemdash{} sit amet \newtextemdash{} consectetuer adipiscing elit.
\guille{Lorem ipsum dolor si amet}
I would like to have this: "<Lorem ipsum dolor sit amet">
\end{document}


The --- is a different machanism it is a ligature built in to the font metrics like replacing f i by the fi ligature.

-
Thank you very much! I suspected something like this for --- and indeed I tried to look for defining new ligatures (like semantic pakage, but not only for math). I didn't know about ''shorthands'', thanks! –  Onner Irotsab Feb 1 at 21:04

Any "shortcut" producing a character has a corresponding command (called the LaTeX internal character representation, LICR).

Thus the shortcut --- can be replaced by \textemdash, while "< and "> (which are babel shortcuts) have the long form \guillemotleft and \guillemotright (the names are historical artifacts due to how Adobe calls them, wrongly).

TeXnically, --- is transformed to an em-dash with a "font ligature" (the same process by which fi becomes a unique glyph), while "< becomes « in a more complicated way involving commands that are only available after \begin{document}. In the preamble it's best to use the LICR.

This said, when the fonts are in the T1 output encoding, there are ligatures also for the guillemets, that is, shortcuts that are always available, also in the preamble.

For the guillemets they are << and >>; so you simply do

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[italian]{babel}

\begin{document}
Lorem ipsum dolor ---~sit amet~--- consectetuer adipiscing elit.

<<Lorem ipsum dolor si amet>>
\end{document}


A command form might be

\newcommand{\guille}[1]{<<#1>>}


or the longer

\newcommand{\guille}[1]{\guillemotleft#1\guillemotright}


However, you can also use the csquotes package and the following input would give the same output. Notice that \enquote picks the right quotation marks, even for nested ones; it is also highly customizable.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[italian]{babel}
\usepackage{csquotes}

\begin{document}
Lorem ipsum dolor ---~sit amet~--- consectetuer adipiscing elit.

\enquote{Lorem ipsum dolor si amet}
\end{document}


-
Thank you very much for your explanation! The only things I knew about obtaining guillemets marks in LaTeX are to use « » (alt+174 alt+175) or << >> or \guillemotleft \guillemotright. But I have noticed that "< and "> have a different output respect of their collegues (that all have the same) and that's why I tried to define \guille with "<#1">. I had tried csquote, but the output was like the one produced by << >>. I would post a picture, but I don't know how to do in this environment... –  Onner Irotsab Feb 1 at 21:18
@OnnerIrotsab I get the same output with "<testo"> and with <<testo>>. Just for completeness (but it's unrelated to the present problem) I recommend you switch to UTF-8 rather than Latin-1 for input encoding as soon as possible. –  egreg Feb 1 at 21:24
I don't know why, but in my output the symbols produced by "<lorem"> are different from those produced by «lorem» or <<lorem>> or \guillemontleft lorem\guillemontright (I have added a picture). However, I did succeed in obtaining my newcommand. Thank you very much for your explanations and suggestions! –  Onner Irotsab Feb 1 at 23:43

For simplicity without babel complications.

\documentclass{minimal}
\newcommand{\encone}[1]{{\fontencoding{T1}\selectfont#1}}
\long\def\"<#1">{\encone{\guillemotleft}#1\encone{\guillemotright}}
\begin{document}
Lorem ipsum dolor --- sit amet --- consectetuer adipiscing elit.
\"<Lorem ipsum dolor si amet">
\end{document}


If you use babel, the following will be easier on typing.

\documentclass{minimal}
\usepackage[english,italian]{babel}

\newcommand{\encone}[1]{{\fontencoding{T1}\selectfont#1}}
\long\def\<#1>{\encone{\guillemotleft}#1\encone{\guillemotright}}
\begin{document}
Lorem ipsum dolor --- sit amet --- consectetuer adipiscing elit.
\<Lorem ipsum dolor si amet>
\end{document}

-
Thank you very much for your answer! I have tried your code, but these codes do not produce the symbols I seek (sorry, I have posted a picture in late). Anyway, it's interesting for me to analize your codes and so improve my knowledge! Thanks! –  Onner Irotsab Feb 1 at 23:58