[OS X TeX] PrettyRef

Sergei Mariev serguei.mariev at campus.lmu.de
Thu Mar 10 16:44:33 EST 2005

Hi Alan,

here is the way I do it. There is one draw-back (see below), but it works ok.

Open Script editor  in the TexShop and create the following macro:

do shell script "perl ~/Documents/scriptsperl/random2.pl"

tell application "TeXShop"
	set the selection of the front document to (the clipboard as text)
end tell

Then save the following perlscript in the path specified in the 
macro, or adjust the path so that the shell script finds the perl 
script attached at the end.

If you look at the script, it does not do anything fancy. It just 
generates a random number between 0 and 9999 and saves it into a 
file. Then it checks the file (random10.txt) to see if the generated 
random number already there. if it is there, it generates another 
one. if it isn't, it creates the \linelabel{NUMBER} string and pipes 
it into the clipboard, which is then pasted into the document. And 
this is the main draw-back: I use pbcopy because I don't know much 
about the Apple Script and I did not have time to learn how to make 
the AppleScript communicate with perl without using the system 
clipboard. So it is slow. Before you use it the first time, create 
the file it looks for in the first place. And adjust all the file 
paths to your system.

Hope you find it usefull,


ps to herb schulz' remark:  you are right! the labels are in this 
case meaningless and generating them randomly is just "an algorithm" 
to do it. You can just start with zero and increment the numebr and 
just save the last one in a file. Would be even easier. Saving them 
in the file is a way to keep track of them, and eventually using 
different files for different projects. I am sure there is a simple 
solution than this. This was just what I came up with in the evening 
when I realized that I need to insert the references in the document 
and don't want to invent them every time and to keep track of them 
manually. I had to save _all_ the labels in the file and not just the 
last one for historical reasons: I started doing this manually and by 
the time I realized I need to do it automatically, there were hundred 
or so labels in my document already. So I had to check to make sure 
that the newly generated label has not been used before.


open(IN, "/Users/sm/Documents/diss/random10.txt") || die "Can't open 
random10.txt: $!\n";

@in = <IN> ;
$howmany = @in;
if ($howmany == 9999) {die "you have used all the keys\n;" }

close IN;


sub dothejob{
     $test = 0;   
     $rnumber = int(rand(9999));
     if ($test == 1) {&dothejob;   
     } else {open(OUT, ">>/Users/sm/Documents/diss/random10.txt") || 
die "Can't open random.txt: $!\n";
	print OUT "$rnumber\n";
	open(PIPE, "| pbcopy");
     print PIPE "\\linelabel\{$rnumber\}";
     close PIPE;

sub testit{
     foreach $member(@in)
     { if ($rnumber == $member) {$test = 1;       

>At 9:07 PM +0100 3/10/05, Sergei Mariev wrote:
>>I think I know the problem. I am working on a critical edition 
>>where I use hundreds (if not thousands) crossreferences. Thinking 
>>up a new lable is quite hard, and it is even harder to remember if 
>>you have already used the label or not, to avoid multiple labels. 
>>What I did in my dissertation was to write a perl script which 
>>generates random labels. Every time it generates a new label, it 
>>appends it to file. Every time it generates a lable itfirst  looks 
>>into the file to see if this number has been in use. Then I wrote a 
>>macro in the TexShop which asks the perl script to generate a label 
>>and pastes it at the current cursor position. This way I can 
>>generate a new label without thinking much about it and I know that 
>>this lablel is unique. Is this something you are looking for?
>Hello, I would be very interested in seeing this.  In linguistics we 
>number each example we discuss, and it would be great to have such a 
>Alan Munn                                                   amunn at msu.edu
>Department of Linguistics                                   amunn at acm.org
>and Germanic, Slavic, Asian and African Languages   Fax.  +1-517-432-2736
>Michigan State University, East Lansing MI 48824    Tel.  +1-517-355-7491
>--------------------- Info ---------------------
>Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
>           & FAQ: http://latex.yauh.de/faq/
>TeX FAQ: http://www.tex.ac.uk/faq
>List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>

--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>

More information about the MacOSX-TeX mailing list