2

I need to change english quotation marks: “text” into german quotation marks: „text“ through out my entire document.

The problem is I used ``text'' and `text' in the entire document.

There is another complication. I also have a lot of greek text in the document which is using both ` and ' to produce accents.

Is there a way to add something to the preamble to change this throughout the document?

Here is my MWE:

\documentclass{scrartcl}
\usepackage[polutonikogreek,ngerman]{babel}%
\usepackage[babel,german=quotes]{csquotes}

\begin{document}
``Double quotes''

`Single quotes'

\foreignlanguage{polutonikogreek}{`ouko~un t~w m`en >agenn'htw patr`i o>ike~ion >ax'iwma fulakt'eon, mhd'ena to~u e@inai a>ut~w t`on a>'ition l'egontas; t~w d`e u<i~w t`hn <arm'ozousan tim`hn >aponemht'eon, t`hn >'anarqon a>ut~w par`a to~u patr`os g'ennhsin >anatij'entas; ka`i <ws >afj'asamen a>ut~w s'ebas >apon'emontes, m'onon e>usebos ka`i e>uf'hmws t`o @hn ka`i t`o `ae'i ka`i t`o pr`o a>i'wnwn l'egontes >ep> a>uto~u, t`hn m'entoi je'othta a>uto~u m`h paraitou'menoi, `all`a t~h e>ik'oni ka`i t~w qarakt~hri to~u patr`os >aphkribwm'enhn >emf'ereian kat`a p'anta >anatij'entes, t`o d`e >ag'ennhton t~w patr`i m'onon >id'iwma pare~inai dox'azontes, <'ate d`h ka`i a>uto~u f'askontos to~u swt~hros; »<o pat'hr mou me'izwn mo'u >estin«.}
\end{document}
stx932
  • 950
  • I thought of renewing command with \renewcommand for left and right quotes as an solution because Latex knows where its a quote and where its greek accent. I don't know which command to renew though – stx932 Jul 16 '14 at 15:53
  • No, the double quotes are not commands that can be renewed. – egreg Jul 16 '14 at 16:26
  • 1
    Use \enquote{random text} if you want to change quotation marks document wide. – Oliver Jul 16 '14 at 18:59
  • I am afraid in 550 pages large document that is not an option. There must be something that can be added to preamble to change this. – stx932 Jul 16 '14 at 19:29
  • Personally I'd use sed: a one line command would fix all of your files, although if you have quotes spanning multiple lines then you'd have to think harder. Alternatively, you might find the post automatic German quotation marks useful. –  Jul 16 '14 at 20:33
  • the problem is I do and a lot. I can't believe there is nobody that can answer this :( – stx932 Jul 18 '14 at 12:05
  • Those quotation marks `` are ligatures like the ff ligature and not a macro that can be redefined... – cgnieder Jul 19 '14 at 07:19
  • 1
    @eklisiarh What is the problem with search & replace (or sed, which is more advanced, as Andrew suggested)? Just search for \`` and replace them with . Then search for '' and replace with . That's half of the job. The single ones need a little more work… could happen that a single quote \`` appears before a word? Or'after a word? Those cases need your explicit decision, since there is no way to differentiate. Otherwise, a regular expresion (sed`) might help. – Manuel Jul 19 '14 at 10:02
  • Which TeX engine do you use? Are you willing and/or able to use LuaLaTeX? – Mico Jul 19 '14 at 11:12
  • @Manuel: The problem is exactly with the single quote which I use almost more than double ones. This is why this type of replacing doesn't work for me (this would only make things worse since I would have german double quotes and english single quotes). – stx932 Jul 19 '14 at 12:32
  • @ Mico: I am using pdflatex and I am not sure I would be willing to change it because there might be some other formatting problems than. – stx932 Jul 19 '14 at 12:33
  • @Manual Unfortunately it can because sometimes its a greek accent for a word on beginning. – stx932 Jul 19 '14 at 12:38
  • That would take a week since the work is so large. I don't think replacing is the way to go. I found this \defineshorthand command which looks like something that could help me. I just need to figure out how to use it. This for example does the work for the double quotes: \AtBeginDocument{% \useshorthands{'} \defineshorthand{''}{\closeautoquote} \useshorthands{} \defineshorthand{``}{\openautoquote} } \AtEndDocument{% \shorthandoff{}% } – stx932 Jul 19 '14 at 12:56
  • @eklisiarh I don't know if it's a week or less, but are there that many possibilites? I mean, if in spanish I needed to differentiate, in a 500 hundred page book, between words that begin with an accent from words that begin with a quote… only six lettes can be accented aeiou and then I would substitute common words… I wouldn't need a week :) – Manuel Jul 19 '14 at 13:06
  • @Manuel Ok thanks for trying! This is actually first time that something in Latex cannot be done by changing the preamble. Who would have thought that such a trivial thing like quotation marks will cause me so much trouble. Anyway I guess I better get onto it... – stx932 Jul 19 '14 at 13:10
  • @eklisiarh It would be great if you added code which does include a few words beginning with an ``` accent inside polutonikogreek so people can see the real problem ;) – Manuel Jul 19 '14 at 13:16
  • @Manuel Ok I will do this! – stx932 Jul 19 '14 at 13:55

1 Answers1

2

Disclaimer: I discovered regular expressions less than a month ago.

This is the easiest way I can think of, since, as others have said, ` and ' are ligatures in the font. This solution works at least in your example.

You need a system that lets you use regular expresions. In my case I used my text editor. Here you have, for instance, an online one (I don't know its limitations) regex101.

Once there, you paste your code in test string. And also open the substitution “tab” which is at the bottom. Now you are going to search and replace with regular expressions which leaves you with the replaced text at the bottom, so each step you need to copy the code in the bottom and paste it again in the top.

  1. Regular expression (\W)`` and substitution \1„.
  2. Regular expression ''(\W) and substitution “\1.
  3. Regular expression (\W)` and substitution \1,. (I used a comma here in the replacemente text since I don't know what you need)
  4. Regular expression '(\W) and substitution ‘\1.

That will leave your example text like

\documentclass{scrartcl}
\usepackage[polutonikogreek,ngerman]{babel}%
\usepackage[babel,german=quotes]{csquotes}

\begin{document}
„Double quotes“

,Single quotes‘

\foreignlanguage{polutonikogreek}{o>uko~un t~w m`en >agenn'htw patr`i o>ike~ion >ax'iwma fulakt'eon, mhd'ena to~u e@inai a>ut~w t`on a>'ition l'egontas; t~w d`e u<i~w t`hn <arm'ozousan tim`hn >aponemht'eon, t`hn >'anarqon a>ut~w par`a to~u patr`os g'ennhsin >anatij'entas; ka`i <ws >afj'asamen a>ut~w s'ebas >apon'emontes, m'onon e>usebos ka`i e>uf'hmws t`o @hn ka`i t`o >ae`i ka`i t`o pr`o a>i'wnwn l'egontes >ep> a>uto~u, t`hn m'entoi je'othta a>uto~u m`h paraitou'menoi, >all`a t~h e>ik'oni ka`i t~w qarakt~hri to~u patr`os >aphkribwm'enhn >emf'ereian kat`a p'anta >anatij'entes, t`o d`e >ag'ennhton t~w patr`i m'onon >id'iwma pare~inai dox'azontes, <'ate d`h ka`i a>uto~u f'askontos to~u swt~hros; »<o pat'hr mou me'izwn mo'u >estin«.}
\end{document}

Which seems right (except for the comma I used instead of an opening low quote :D).


A little explanation. \W searches for a non-letter (that is, something that is not [a-zA-Z0-9_], with the parenthesis (\W) you save its content into \1. So searching for '(\W) will search for a quote and a non letter which removes the possibility of selecting it when it's inside a word. Now the replacement is ‘\1 which is what you want, you change the quote and re-insert the non-letter you grabbed in the search (so you don't loose it).

Manuel
  • 27,118
  • This answer solves the code in the question. Although, as @eklisiarh said in a comment, it has only a flaw: inside polutonikogreek there may be words which begin with (an accent) ```, which have been converted to an opening single quote during this process. I might know how to do it with regular expressions, but it's not straightforward, so, in case anyone knows, feel free to edit. – Manuel Jul 19 '14 at 13:03
  • Do you by any chance know how I could replace all words inside the \grk{} command that begin with whitespace and an accent ` with something like whitespace$. That way I could replace the other things and than replace these things back. – stx932 Feb 04 '16 at 11:11