From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/72066 Path: news.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: ConvertToConteXt - convert special ConTeXt-characters (PHP) Date: Tue, 1 Nov 2011 13:54:09 -0400 (EDT) Message-ID: References: <4EB01B4D.2070601@gmx.de> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1233779664-1320170051=:8760" X-Trace: dough.gmane.org 1320170076 7307 80.91.229.12 (1 Nov 2011 17:54:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 1 Nov 2011 17:54:36 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Nov 01 18:54:32 2011 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RLIXf-0000YY-TT for gctc-ntg-context-518@m.gmane.org; Tue, 01 Nov 2011 18:54:31 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 3C41ACB0AD; Tue, 1 Nov 2011 18:54:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Su1lE9AqPEiY; Tue, 1 Nov 2011 18:54:28 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 61B2BCB0A8; Tue, 1 Nov 2011 18:54:28 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B3167CB0A8 for ; Tue, 1 Nov 2011 18:54:26 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MBy+UYtDEDEo for ; Tue, 1 Nov 2011 18:54:15 +0100 (CET) Original-Received: from filter4-ams.mf.surf.net (filter4-ams.mf.surf.net [192.87.102.72]) by balder.ntg.nl (Postfix) with ESMTP id ECD0FCB098 for ; Tue, 1 Nov 2011 18:54:14 +0100 (CET) Original-Received: from tombraider.mr.itd.umich.edu (smtp.mail.umich.edu [141.211.12.86]) by filter4-ams.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id pA1HsCwS025542 for ; Tue, 1 Nov 2011 18:54:14 +0100 Original-Received: FROM [10.0.2.15] (wpa045090.Wireless.McGill.CA [142.157.45.90]) By tombraider.mr.itd.umich.edu ID 4EB03243.3399F.18584 ; Authuser adityam; 1 Nov 2011 13:54:11 EDT In-Reply-To: <4EB01B4D.2070601@gmx.de> User-Agent: Alpine 2.02 (LNX 1266 2009-07-14) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=141.211.12.86; country=US; region=MI; city=Ann Arbor; postalcode=48109; latitude=42.2923; longitude=-83.7145; metrocode=505; areacode=734; http://maps.google.com/maps?q=42.2923,-83.7145&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 03FPRScQF - 4458591ff557 - 20111101 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.72 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:72066 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-1233779664-1320170051=:8760 Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 1 Nov 2011, Jan Heinen wrote: > Hello, > > I am just programming a catalog which should be printed. > > I have a lot of data, text and pictures in a MySQL-database and want to= =20 > generate a nice catalog with ConTeXt. > To get the data from MySQL to ConTeXt I use PHP as an Interface: > > MySQL -> PHP -> ConTeXt > > And lot's of ConTeXt-macros will make a nice layout :-) > > To give something back to this ConTeXt-community, I will put some helpful= l=20 > PHP-functions into the wiki of contextgarden.net. > > Today I wrote the function "ConvertToConteXt" which converts special=20 > ConTeXt-characters. You can see it below. > > > Before I put it into contextgarden.net ... > 1. ... please test it. > 2. You see three characters, where I don't know the code-number \char??? = for=20 > ConTeXt. Do you know them? > 3. Did I forget to convert a character? > > Regards > Jannis > > > > function ConvertToConteXt ( $xstring ) { > /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = * *=20 > * > * > * author: J=C3=B6rg Kopp > * www.dr-kopp.com > * 01.11.2011 > * > * Convert special ConTeXt-characters with php > * Works with PHP5 > * > * Call it with the string you want to convert ... > * ConvertToConteXt ($xstring); > * > * ... and you get back the converted string > * > * e.g.: > * Input: > * $string =3D "My root-Directory: /home/hans"; > * $string =3D ConvertToConteXt ( $string ); > * > * Output/Return: > * $string =3D "My root\\char45Directory\\char58=20 > \\char47home\\char47hans"; > * > * When you write this into a file ... > * file_put_contents ( "example.tex", "My=20 > root\\char45Directory\char58 \\char47home\\char47hans", FILE_APPEND ); > * > * ... You will find the following in example.tex: > * My root\char45Directory\char58 \char47home\char47hans > * > * An when you compile example.tex with ConTeXt > * context example.text > * > * You can read the following in the resulting example.pdf: > * My root-Directory: /home/hans > * > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= */ > > $xstring =3D html_entity_decode ( $xstring ); // convert=20 > HTML-entities into normal characters > $xstring =3D str_replace ( "!", "\\char33", $xstring ); //=20 > Ausrufungszeichen/ConvertToConteXt > $xstring =3D str_replace ( "\"", "\\char34", $xstring ); //=20 > Anf=C3=BChrungszeichen/quotation mark > $xstring =3D str_replace ( "#", "\\char35", $xstring ); // Raute/numbe= r=20 > sign > $xstring =3D str_replace ( "$", "\\char36", $xstring ); //=20 > Dollar-Zeichen/dollar sign > $xstring =3D str_replace ( "%", "\\char37", $xstring ); //=20 > Prozent-Zeichen/percent sign > $xstring =3D str_replace ( "&", "\\char38", $xstring ); // Kaufm=C3=A4= nnisches=20 > Und/ampersand > $xstring =3D str_replace ( "'", "\\char39", $xstring ); //=20 > Apostroph/apostrophe > $xstring =3D str_replace ( "(", "\\char40", $xstring ); // Klammer auf= /left=20 > parenthesis > $xstring =3D str_replace ( ")", "\\char41", $xstring ); // Klammer zu/= right=20 > parenthesis > $xstring =3D str_replace ( "*", "\\char42", $xstring ); // Stern/aster= isk > $xstring =3D str_replace ( "+", "\\char43", $xstring ); // Plus/plus s= ign > $xstring =3D str_replace ( ",", "\\char44", $xstring ); // Komma/comma > $xstring =3D str_replace ( "-", "\\char45", $xstring ); // Minus/hyphe= n > $xstring =3D str_replace ( ".", "\\char46", $xstring ); // Punkt/perio= d > $xstring =3D str_replace ( "/", "\\char47", $xstring ); //=20 > Schr=C3=A4gstrich/period > $xstring =3D str_replace ( ":", "\\char58", $xstring ); //=20 > Doppelpunkt/colon > $xstring =3D str_replace ( ";", "\\char59", $xstring ); //=20 > Semikolon/semicolon > $xstring =3D str_replace ( "<", "\\char60", $xstring ); //=20 > Kleinerzeichen/less-than > $xstring =3D str_replace ( "=3D", "\\char61", $xstring ); //=20 > Gleichzeichen/equals-to > $xstring =3D str_replace ( ">", "\\char62", $xstring ); //=20 > Gr=C3=B6=C3=9Ferzeichen/greater-than > $xstring =3D str_replace ( "?", "\\char63", $xstring ); //=20 > Fragezeichen/question mark > $xstring =3D str_replace ( "@", "\\char64", $xstring ); // at-Zeichen/= at=20 > sign > $xstring =3D str_replace ( "[", "\\char91", $xstring ); // eckige Klam= mer=20 > auf/left square bracket > $xstring =3D str_replace ( "\\", "\\char92", $xstring ); //=20 > Backslash/backslash > $xstring =3D str_replace ( "]", "\\char93", $xstring ); // eckige Klam= mer=20 > zu/right square bracket > $xstring =3D str_replace ( "^", "\\char94", $xstring ); // Zirkumflex/= caret > $xstring =3D str_replace ( "_", "\\char95", $xstring ); //=20 > Unterstrich/underscore > //$xstring =3D str_replace ( "=C2=B0", "\\char", $xstring ); // Grad/ = < ------=20 > missing > $xstring =3D str_replace ( "`", "\\char96", $xstring ); // accent=20 > aigu/acute accent > $xstring =3D str_replace ( "{", "\\char123", $xstring ); // geschweifte= =20 > Klammer auf/left curly brace > $xstring =3D str_replace ( "|", "\\char124", $xstring ); //=20 > Pipezeichen/vertical bar > $xstring =3D str_replace ( "}", "\\char125", $xstring ); // geschweifte= =20 > Klammer zu/right curly brace > $xstring =3D str_replace ( "~", "\\char126", $xstring ); // Tilde/tild= e > //$xstring =3D str_replace ( "=E2=80=A2", "\\char", $xstring ); // ?/ = < ------=20 > missing > //$xstring =3D str_replace ( "=C2=BA", "\\char", $xstring ); // ?/ < -= -----=20 > missing > > return $xstring; > } This is what I use in t-vim " Change special TeX characters to escape sequences. let s:temp =3D escape( s:temp, '\{}') and read everything in a catcode regime that sets only \ { } to their=20 regular meaning. Aditya --0-1233779664-1320170051=:8760 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --0-1233779664-1320170051=:8760--