如何将常规引号(即',")转换为LaTeX/TeX引号(即`',``'') [英] How can one turn regular quotes (i.e. ', ") into LaTeX/TeX quotes (i.e. `', ``'')

查看:14
本文介绍了如何将常规引号(即',")转换为LaTeX/TeX引号(即`',``'')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个用普通引号写的文档,例如

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 会产生:

So that LaTeX produces:

Ben said "buttons, dear sir".
I replied "Did you say ‘buttons’?"

我的第一个想法是转向正则表达式.但是,我没有从 Google 或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.

最大的问题将与识别未配对的单个 "'" 相关联——就像收缩("'" 中的 >不"不应更改,不应配对).

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]+

仅限于单词中间有 "'" 的缩写.除了 squotedquote 术语会酌情替换引号之外,所有关联的操作都只会回显输入.

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引号(即`',``'')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆