emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 3cd62d043e266ca265ffc06dff26642c7c7d5213 3429 bytes (raw)
name: mk/orgcard2txt.pl 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
# orgcard2txt.pl - a script to generate orgcard.txt from orgcard.tex
# Copyright (C) 2010, 2013 Osamu OKANO
#
# Version: 0.1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Usage:
# ======
#  perl orgcard2txt.pl orgcard.tex > orgcard.txt
use strict;
use warnings;

sub rep_esc{
  my $s = shift @_;
  $s =~ s/\\kbd{([^}]+)}/$1/g;
  $s =~ s/\$\^([0-9])\$/[$1]/g;
  $s =~ s/\\rm //g;
  $s =~ s/\\\///g;
  $s =~ s/\\\^{}/^/g;
  $s =~ s/\\}/}/g;
  $s =~ s/\\{/{/g;
  $s =~ s/\\\#/#/g;
  $s =~ s/\\\^/^/g;
  $s =~ s/\\\%/%/g;
  $s =~ s/\\\_/_/g;
  $s =~ s/\\\&/&/g;
  $s =~ s/\\\$/\$/g;
  $s =~ s/\$\\leftrightarrow\$/<->/g;
  $s =~ s/\$\\pm 1\$/±1/g;
  $s =~ s/``{\\tt ([^}]+)}''/`$1'/g;
  return $s;
}
my $page=0;
my $orgversionnumber;

open(IN,$ARGV[0]);
while(<IN>){
  last if(/\f/);
  $orgversionnumber = $1 if /\\def\\orgversionnumber{([^}]+)}/;
}
close(IN);

print <<HEAD;
================================================================================
Org Mode Reference Card (for version $orgversionnumber)
================================================================================
HEAD

my $key;
my $value;

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$key,$value
.

open(IN,$ARGV[0]);
while(<IN>){
  if(/\f/){
    $page = $page + 1;
    next;
  }
  next if($page != 1);
  next if(/^%/);
  next if /Org Mode Reference Card \([12]\/2\)/;
  next if /\\centerline{\(for version \\orgversionnumber\)}/;
  next if /\(for version  \)/;
  next if /\\newcolumn/;
  next if /\\copyrightnotice/;
  next if /\\bye/;
  next if /\\title{([^}]+)}/;
  chomp;
#  print "b:$_\n";
  s/([^\\])\%.+$/$1/;
#  print "a:$_\n";
  if (/\\section{(.+)}/){
    my $sec = rep_esc($1);
    print "================================================================================\n";
    print "$sec\n";
    print "================================================================================\n";
    next;
  }
  if (/{\\bf (.+)}/){
    my $bf = rep_esc($1);
    print "--------------------------------------------------------------------------------\n";
    print "$bf\n";
    print "--------------------------------------------------------------------------------\n";
    next;
  }
  if (/^{\\it (.+)}/){
    my $it = rep_esc($1);
    print "--------------------------------------------------------------------------------\n";
    print "$it\n";
    print "--------------------------------------------------------------------------------\n";
    next;
  }
  if(/^\\key{(.+)}\s*$/||/^\\metax{(.+)}\s*$/){
    my ($k,$v) = split(/}{/,$1);
    my $k2 = &rep_esc($k);
    my $v2 = &rep_esc($v);
#    print "$k2\t$v2\n";
    ($key,$value)=($k2,$v2);
    write;
    next;
  }
  my $line = rep_esc($_);
  $line =~ s/{\\it ([^}]+)}/$1/g;
  $line =~ s/{\\tt ([^}]+)}/$1/g;
  print "$line\n";
}
close(IN);

debug log:

solving 3cd62d043 ...
found 3cd62d043 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).