Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to be able to manually redefine quotation mark usage, preferably without having to load an external package.

Judging by the answer to How does TeX's mechanism for sorting out quotation marks work?, it seems that TeX and LaTeX use fonts that feature built-in ligatures to handle quotation mark conversion, while XeTeX and XeLaTeX refer to a map file that has the same function. The quotation marks are effectively ligatures, and not directly defined by the typesetting system.

However, I would like to be able to directly define the expected quotation mark result.

For example, I would like to define commands similar to the following (which do not work):

\def```{\char"201C\char"202F\char"2018\relax}

which should render as something like “‘.

\def'''{\char"2019\char"202F\char"201D\relax}

which should render as something like ’”.

I would prefer a solution that could use any character or set of characters as the replacement, because I may have to customize the usage further in the future.

share|improve this question
2  
You can't do it in this way. Ligatures are substituted well down the digestion process, when macros are not a factor any more. Are you using XeLaTeX? –  egreg Nov 5 '12 at 10:22

1 Answer 1

up vote 1 down vote accepted

It might be overkill, but I've found that one can achieve this through the use of LaTeX3's regular expression system.

The first thing to do is to disable the default TeX ligatures in a manner similar to the following:

\setmainfont[Ligatures={Common}, BoldFont={Calluna Semibold}]{Calluna}

Then define a command to perform a find and replace process on the text in a manner similar to the following:

\tl_new:N \l_demo
\cs_new:Npn \demo #1 {
    \tl_set:Nn \l_demo {#1}
    \regex_replace_all:nnN {\`\`\`} {“‘} \l_demo
    \regex_replace_all:nnN {\'\'\'} {’”} \l_demo
    \tl_use:N \l_demo
}

The command can be called in the following manner:

\demo{```These are fancy quotation marks.'''}

I am not sure if it is possible to have the \demo command automatically encompass the document environment, but if it is possible, that would effectively automate the process.

And of course, one might want to reimplement (some of) the default TeX ligatures using this method, seeing as they have already been disabled.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.