org.texi: Fix small typo.
[org-mode.git] / UTILITIES / orgcard2txt.pl
blobc5d942cf5368ec1e5a4e48492044b327ac3d2230
1 # orgcard2txt.pl - a script to generate orgcard.txt from orgcard.tex
2 # Copyright (C) 2010 Osamu OKANO
4 # Version: 0.1
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Usage:
20 # ======
21 # perl orgcard2txt.pl orgcard.tex > orgcard.txt
22 use strict;
23 use warnings;
25 sub rep_esc{
26 my $s = shift @_;
27 $s =~ s/\\kbd{([^}]+)}/$1/g;
28 $s =~ s/\$\^([0-9])\$/[$1]/g;
29 $s =~ s/\\rm //g;
30 $s =~ s/\\\///g;
31 $s =~ s/\\\^{}/^/g;
32 $s =~ s/\\}/}/g;
33 $s =~ s/\\{/{/g;
34 $s =~ s/\\\#/#/g;
35 $s =~ s/\\\^/^/g;
36 $s =~ s/\\\%/%/g;
37 $s =~ s/\\\_/_/g;
38 $s =~ s/\\\&/&/g;
39 $s =~ s/\\\$/\$/g;
40 $s =~ s/\$\\leftrightarrow\$/<->/g;
41 $s =~ s/\$\\pm 1\$/±1/g;
42 $s =~ s/``{\\tt ([^}]+)}''/`$1'/g;
43 return $s;
45 my $page=0;
46 my $orgversionnumber;
48 open(IN,$ARGV[0]);
49 while(<IN>){
50 last if(/\f/);
51 $orgversionnumber = $1 if /\\def\\orgversionnumber{([^}]+)}/;
53 close(IN);
55 print <<HEAD;
56 ================================================================================
57 Org-Mode Reference Card (for version $orgversionnumber)
58 ================================================================================
59 HEAD
61 my $key;
62 my $value;
64 format STDOUT =
65 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
66 $key,$value
69 open(IN,$ARGV[0]);
70 while(<IN>){
71 if(/\f/){
72 $page = $page + 1;
73 next;
75 next if($page != 1);
76 next if(/^%/);
77 next if /Org-Mode Reference Card \([12]\/2\)/;
78 next if /\\centerline{\(for version \\orgversionnumber\)}/;
79 next if /\(for version \)/;
80 next if /\\newcolumn/;
81 next if /\\copyrightnotice/;
82 next if /\\bye/;
83 next if /\\title{([^}]+)}/;
84 chomp;
85 # print "b:$_\n";
86 s/([^\\])\%.+$/$1/;
87 # print "a:$_\n";
88 if (/\\section{(.+)}/){
89 my $sec = rep_esc($1);
90 print "================================================================================\n";
91 print "$sec\n";
92 print "================================================================================\n";
93 next;
95 if (/{\\bf (.+)}/){
96 my $bf = rep_esc($1);
97 print "--------------------------------------------------------------------------------\n";
98 print "$bf\n";
99 print "--------------------------------------------------------------------------------\n";
100 next;
102 if (/^{\\it (.+)}/){
103 my $it = rep_esc($1);
104 print "--------------------------------------------------------------------------------\n";
105 print "$it\n";
106 print "--------------------------------------------------------------------------------\n";
107 next;
109 if(/^\\key{(.+)}\s*$/||/^\\metax{(.+)}\s*$/){
110 my ($k,$v) = split(/}{/,$1);
111 my $k2 = &rep_esc($k);
112 my $v2 = &rep_esc($v);
113 # print "$k2\t$v2\n";
114 ($key,$value)=($k2,$v2);
115 write;
116 next;
118 my $line = rep_esc($_);
119 $line =~ s/{\\it ([^}]+)}/$1/g;
120 $line =~ s/{\\tt ([^}]+)}/$1/g;
121 print "$line\n";
123 close(IN);