From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: ConvertToConteXt - convert special ConTeXt-characters (PHP)
Date: Tue, 1 Nov 2011 13:54:09 -0400 (EDT) [thread overview]
Message-ID: <alpine.LNX.2.02.1111011352120.8760@nqv-gnoyrg> (raw)
In-Reply-To: <4EB01B4D.2070601@gmx.de>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 5796 bytes --]
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
> 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 helpfull
> PHP-functions into the wiki of contextgarden.net.
>
> Today I wrote the function "ConvertToConteXt" which converts special
> 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
> ConTeXt. Do you know them?
> 3. Did I forget to convert a character?
>
> Regards
> Jannis
>
>
>
> function ConvertToConteXt ( $xstring ) {
> /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> *
> *
> * author: Jörg 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 = "My root-Directory: /home/hans";
> * $string = ConvertToConteXt ( $string );
> *
> * Output/Return:
> * $string = "My root\\char45Directory\\char58
> \\char47home\\char47hans";
> *
> * When you write this into a file ...
> * file_put_contents ( "example.tex", "My
> 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 = html_entity_decode ( $xstring ); // convert
> HTML-entities into normal characters
> $xstring = str_replace ( "!", "\\char33", $xstring ); //
> Ausrufungszeichen/ConvertToConteXt
> $xstring = str_replace ( "\"", "\\char34", $xstring ); //
> Anführungszeichen/quotation mark
> $xstring = str_replace ( "#", "\\char35", $xstring ); // Raute/number
> sign
> $xstring = str_replace ( "$", "\\char36", $xstring ); //
> Dollar-Zeichen/dollar sign
> $xstring = str_replace ( "%", "\\char37", $xstring ); //
> Prozent-Zeichen/percent sign
> $xstring = str_replace ( "&", "\\char38", $xstring ); // Kaufmännisches
> Und/ampersand
> $xstring = str_replace ( "'", "\\char39", $xstring ); //
> Apostroph/apostrophe
> $xstring = str_replace ( "(", "\\char40", $xstring ); // Klammer auf/left
> parenthesis
> $xstring = str_replace ( ")", "\\char41", $xstring ); // Klammer zu/right
> parenthesis
> $xstring = str_replace ( "*", "\\char42", $xstring ); // Stern/asterisk
> $xstring = str_replace ( "+", "\\char43", $xstring ); // Plus/plus sign
> $xstring = str_replace ( ",", "\\char44", $xstring ); // Komma/comma
> $xstring = str_replace ( "-", "\\char45", $xstring ); // Minus/hyphen
> $xstring = str_replace ( ".", "\\char46", $xstring ); // Punkt/period
> $xstring = str_replace ( "/", "\\char47", $xstring ); //
> Schrägstrich/period
> $xstring = str_replace ( ":", "\\char58", $xstring ); //
> Doppelpunkt/colon
> $xstring = str_replace ( ";", "\\char59", $xstring ); //
> Semikolon/semicolon
> $xstring = str_replace ( "<", "\\char60", $xstring ); //
> Kleinerzeichen/less-than
> $xstring = str_replace ( "=", "\\char61", $xstring ); //
> Gleichzeichen/equals-to
> $xstring = str_replace ( ">", "\\char62", $xstring ); //
> Größerzeichen/greater-than
> $xstring = str_replace ( "?", "\\char63", $xstring ); //
> Fragezeichen/question mark
> $xstring = str_replace ( "@", "\\char64", $xstring ); // at-Zeichen/at
> sign
> $xstring = str_replace ( "[", "\\char91", $xstring ); // eckige Klammer
> auf/left square bracket
> $xstring = str_replace ( "\\", "\\char92", $xstring ); //
> Backslash/backslash
> $xstring = str_replace ( "]", "\\char93", $xstring ); // eckige Klammer
> zu/right square bracket
> $xstring = str_replace ( "^", "\\char94", $xstring ); // Zirkumflex/caret
> $xstring = str_replace ( "_", "\\char95", $xstring ); //
> Unterstrich/underscore
> //$xstring = str_replace ( "°", "\\char", $xstring ); // Grad/ < ------
> missing
> $xstring = str_replace ( "`", "\\char96", $xstring ); // accent
> aigu/acute accent
> $xstring = str_replace ( "{", "\\char123", $xstring ); // geschweifte
> Klammer auf/left curly brace
> $xstring = str_replace ( "|", "\\char124", $xstring ); //
> Pipezeichen/vertical bar
> $xstring = str_replace ( "}", "\\char125", $xstring ); // geschweifte
> Klammer zu/right curly brace
> $xstring = str_replace ( "~", "\\char126", $xstring ); // Tilde/tilde
> //$xstring = str_replace ( "•", "\\char", $xstring ); // ?/ < ------
> missing
> //$xstring = str_replace ( "º", "\\char", $xstring ); // ?/ < ------
> missing
>
> return $xstring;
> }
This is what I use in t-vim
" Change special TeX characters to escape sequences.
let s:temp = escape( s:temp, '\{}')
and read everything in a catcode regime that sets only \ { } to their
regular meaning.
Aditya
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2011-11-01 17:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-01 16:16 Jan Heinen
2011-11-01 17:21 ` Peter Münster
2011-11-01 17:54 ` Aditya Mahajan [this message]
2011-11-01 17:58 ` Philipp Gesang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LNX.2.02.1111011352120.8760@nqv-gnoyrg \
--to=adityam@umich.edu \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).