From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: How to translate LaTeX into UTF-8 in Elisp? Date: Tue, 04 Jul 2017 07:57:53 +0200 Message-ID: <87o9t0217i.fsf@jane> References: <87shpyfj2q.fsf@mbork.pl> <87bmp2rud7.fsf@jane> <87bmp1ykzh.fsf@imladris.arda> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1499147917 25767 195.159.176.226 (4 Jul 2017 05:58:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Jul 2017 05:58:37 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 26.0.50 Cc: Help Gnu Emacs mailing list To: Teemu Likonen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 04 07:58:33 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSGr1-0006Nv-OC for geh-help-gnu-emacs@m.gmane.org; Tue, 04 Jul 2017 07:58:31 +0200 Original-Received: from localhost ([::1]:38741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSGr7-0002UK-2u for geh-help-gnu-emacs@m.gmane.org; Tue, 04 Jul 2017 01:58:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSGqe-0002UF-9V for help-gnu-emacs@gnu.org; Tue, 04 Jul 2017 01:58:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSGqa-0004Xv-Dx for help-gnu-emacs@gnu.org; Tue, 04 Jul 2017 01:58:08 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:39980) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSGqa-0004Xg-6f for help-gnu-emacs@gnu.org; Tue, 04 Jul 2017 01:58:04 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 7DB24E6669; Tue, 4 Jul 2017 07:58:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l47dCgmTMrd4; Tue, 4 Jul 2017 07:57:58 +0200 (CEST) Original-Received: from localhost (static-dwadziewiec-jedenpiec7.echostar.pl [109.232.29.157]) by mail.mojserwer.eu (Postfix) with ESMTPSA id EBFBFE62DE; Tue, 4 Jul 2017 07:57:57 +0200 (CEST) In-reply-to: <87bmp1ykzh.fsf@imladris.arda> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.110.48.8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:113684 Archived-At: On 2017-07-03, at 10:37, Teemu Likonen wrote: > Marcin Borkowski [2017-07-03 06:56:36+02] wrote: > >> On 2016-12-08, at 18:04, Marcin Borkowski wrote: >>> I have a string with embedded sequences like "\'e" or "\H{o}". The >>> Emacs TeX input method knows how to convert them into "=C3=A9" or "=C5= =91" (when >>> typing, of course). Is there a way to use that to perform similar >>> conversions in a string? > >> I'm revisiting this old thread now. > >> It is a horrible hack, but it should work. Any better ideas? > > I would filter buffer's content through recode command. > > [Highlight a region.] > > C-u M-x shell-command-on-region RET recode tex.. RET > > You wanted to do this for a string so we can write a function that uses > a temporary buffer and returns its content as a string. Here is a quick > example: > > (defun convert-from-latex (string) > (with-temp-buffer > (insert string) > (call-process-region (point-min) (point-max) > "recode" t t nil "tex..") > (buffer-substring-no-properties (point-min) (point-max)))) Thanks, I didn't know about recode. But it doesn't work all that well: c{\c c}c does not remove braces, for instance, and what's even worse, it apparently doesn't know about \k. But thanks anyway, this is a good thing to remember, even though in my case I perceive it as even more hackish than my approach (I'd prefer Emacs to do the job, not an external utility). Best, --=20 Marcin Borkowski