问题描述
给出一个带有普通引号的文档,例如
Given a document written with normal quotes, e.g.
Ben said "buttons, dear sir".
I replied "Did you say 'buttons'?" to him.
使用适当的语义,可以通过什么样的方式将这些东西转换为LaTeX引号.即
What ways can one turn these sort of things into LaTeX quotes, with the appropriate semantics. i.e.
Ben said ``buttons, dear sir''.
I replied ``Did you say `buttons'?'' to him.
以便LaTeX产生:
Ben said "buttons, dear sir".
I replied "Did you say ‘buttons’?"
我的第一个想法是转向正则表达式.但是,我没有从Google或regex库中获得任何关于"LaTeX引用正则表达式"的信息,当然,"TeX引用正则表达式"似乎返回了太多.
My first thought is to turn to a regex. However, I'm not getting any hits from Google or the regex libraries for "LaTeX quotes regular expression", and of course "TeX quotes regular expression" seems to return too many.
谢谢.
推荐答案
通常,此问题比看起来要难.
In general, this problem is harder than it looks.
最简单的情况 可以用正则表达式处理,但是对于更一般的情况,您几乎肯定需要构建一个递归解析器:正则表达式仅在没有嵌套的情况下才起作用.
The simplest cases can be treated with regular expressions, but for more general situations you will almost certainly need to build a recursive parser: regular expression will only work if there is no nesting.
最大的问题将是与识别未配对的单个"'"
相关联-收缩也是如此("don't"
中的"'"
不应更改,和不应该配对).
The big problem is going to be associated with identifying single "'"
s that are not paired---as is contractions (the "'"
in "don't"
should not be changed, and should not be paired).
让我们看看是否可以编写可用的EBNF描述:
Lets see if we can write a usable EBNF description:
input: text+
text: uquote|squote|dquote
squote "'" text "'"
dquote """ text """
uquote: [contraction|.]+
contraction: [A-Za-z]+ "'" [A-Za-z]+
仅限于单词中间带有"'"
的收缩.除了squote
和dquote
术语会酌情替换引号之外,所有与之相关的动作只会回显输入.
which is limited to contractions that have the "'"
in the middle of the word. All the associated action will just echo the input, except that the squote
and dquote
terms replace the quotes as appropriate.
我使用了正则表达式,然后进行了人工修正,从而实现了非常简单的一次性操作,但这对于正在进行的工作将是劳动密集型的.
I used regular expressions followed by human fix-ups for a fairly simple one-off, but that would be labor intensive for on-going work.
这篇关于如何将常规引号(即',')转换为LaTeX/TeX引号(即'',``'')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!