I am writing a tex document using book document class. I have already typed close to 100 pages, but i did a mistake with typing single and double quotes. I have done it as follows : "test double quotes" and 'test double quotes' which generated the output of the form : enter image description here

Is there a way i can generate the correct output without changing the quotes in all the places ? I saw some similar answers @ Isn't there any other way of doing double quotes in LaTeX besides `` + ''? but none seemed to work.


Here's a LuaLaTeX-based solution, which doesn't require you to modify the existing "..." and '...' pairs of quotes. It consists of a Lua function called msq (short for 'make smart quotes') and two utility LaTeX macros which switch the Lua function on and off.

enter image description here

\usepackage[english]{babel} % or some other suitable language choice

-- msq: "make smart quotes"
function msq ( s ) 
  s = s:gsub ( '"(.-)"' , "\\enquote{%1}" )
  s = s:gsub ( "'(.-)'" , "`%1'" )
  return s

\newcommand{\msqOn}{\directlua{  luatexbase.add_to_callback( 
   "process_input_buffer", msq , "msq" )}}
\newcommand{\msqOff}{\directlua{ luatexbase.remove_from_callback( 
   "process_input_buffer", "msq" )}}

"test double quotes" and 'test single quotes'

 "\,'Twas brillig and the slithy toves \ldots"

"test double quotes" and 'test single quotes'
  • What happens when you're quoting " 'Twas brillig and the slithy toves ..."? – barbara beeton Jul 15 at 1:10
  • @barbarabeeton - Actually, that case is handled just fine by my code. :-) I'll edit my MWE to demonstrate it. – Mico Jul 15 at 4:00
  • @Mico : Thanks for your answer. I need to use xeLatex (as i am using fontspec pkg). And while compiling this, it needs luaLatex. Is there a way, i can compile this code with xeLatex as well ? – mezda Jul 15 at 4:16
  • @mezda - The fontspec package works equally well under both LuaLaTeX and XeLaTeX. Using fontspec in no way precludes the use of LuaLaTeX. – Mico Jul 15 at 4:20
  • 1
    Oh, I'm just being difficult. But that is a plausible scenario, so I'm suggesting that generality is a "good thing". – barbara beeton Jul 15 at 13:26

Replace at first the last quote with the editor and "Search and Replace"

"<space>  -> }

Then repcae the first quote with

" -> \enquote{

and then use always:




\enquote{quote \enquote{quote in quote}}


\foreignquote{ngerman}{quote \foreignquote{ngerman}{quote in quote}}


\foreignquote{french}{quote \foreignquote{ngerman}{quote in quote}}


enter image description here

  • 2
    The OP asked whether "there [is] a way i can generate the correct output without changing the quotes in all the places?" – Mico Jul 14 at 18:53
  • Your substitution rule, "<space> -> }, doesn't catch the cases when the closing " character occurs at the very end of a line or is followed by a punctuation character. – Mico Jul 15 at 4:05
  • 1
    The significant part of the question is that the user doesn't want to go and fix all their straight quotes " to the proper (or `` in traditional TeX) and (or '' in traditional TeX), i.e. determine which straight quote should be changed to which. Obviously, determining which ones should be \enquote{ and which ones should be } is the same problem; so this isn't any simpler and doesn't answer anything. Sure, using enquote helps if using multiple languages and quotation styles, but the question mentions nothing about using multiple quotation-mark styles. – ShreevatsaR Jul 15 at 4:48

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.