将非ASCII/UTF-8字符转换为LaTeX代码 [英] Convert non-ASCII/UTF-8 characters into LaTeX codes

查看:126
本文介绍了将非ASCII/UTF-8字符转换为LaTeX代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须将非ASCII,UTF-8或命名实体字符转换为LaTeX代码.现在我们使用非ASCII到Unicode,然后使用Perl脚本将Unicode到LaTeX/entity.

We have to convert non-ASCII, UTF-8, or named entity characters into LaTeX codes. Now we are using non-ASCII to Unicode, then Unicode to LaTeX/entity using a Perl script.

例如:

 ó --> \'{o}
 ó --> \'{o}
 ó --> \'{o}

Perl程序/脚本中是否有从非ASCII或UTF-8到LaTeX代码的直接转换?

Is there any direct conversion from non-ASCII, or UTF-8 to LaTeX codes in Perl program/script?

推荐答案

使用 XML::Entities 模块解码实体,然后 LaTeX::Encode 模块重新解码-将它们编码为LaTeX

This is very straightforward using the XML::Entities module to decode the entities, and the LaTeX::Encode module to re-encode them as LaTeX

请注意,我已经为解码功能明确创建了别名xml_decode,因为导出的名称仅为decode,这太不精确了

Note that I've explicitly created an alias xml_decode for the decoding function, as the exported name is just decode, which is far too imprecise

use utf8;
use strict;
use warnings 'all';
use feature 'say';

use XML::Entities ();
use LaTeX::Encode 'latex_encode';
*xml_decode = \&XML::Entities::decode;

for my $s ( 'ó', 'ó', 'ó' ) {
    my $reencoded = latex_encode(xml_decode('all', $s));
    say $reencoded;
}

输出

{\'o}
{\'o}
{\'o}

这篇关于将非ASCII/UTF-8字符转换为LaTeX代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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