cavac has asked for the wisdom of the Perl Monks concerning the following question:

I was looking into learning PDL. I see there's the PDL Book linked on the official site, but unfortunately it's in PDF format. I can work with that, but an epub format for my ePaper reader would be preferable. The PDF has awfully small print, at least for my old, worn-out eyes. Yes, i could zoom the PDF, which makes for a suboptimal reading experience, so i'd prefer a format that i can reflow with bigger fonts.

Any chance something like this exists?

Replies are listed 'Best First'.
Re: PDL Book as epub?
by LanX (Saint) on Aug 09, 2024 at 09:52 UTC
    I was fiddling with ePUB recently, and it's basically glorified HTML in a zipped directory structure.

    The book you mentioned seems to be that one downloadable for free here https://pdl.perl.org/content/pdl-book-toc.html (and I doubt that the fonts are inaccessible)

    So you could go and try a PDF to HTML converter and build your own ePUB.

    There are even free online services for PDF to ePUB, can't comment on the quality.

    I suppose you'll have to adjust some parameters afterwards but I'm confident you have the necessary skills ;)

    HTH

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      I realized that the link I gave is not the newest version, and while investigating I got the impression that the book was created from a POD source.

      Then I stumbled over this

      https://sourceforge.net/p/pdl/pdl-book/ci/master/tree/

      Please note the included scripts to build a PDF and even an all in one HTML.

      See also the sub directories with a POD file per chapter.

      Starting from there it should be easy to write a script to build ePUB from POD. You may even contribute it to the project.

      Disclaimer: no guarantee whatsoever for the actuality of the links given. I'm not part of this community and I find the repository structure kind of confusing.

      Update
      Maybe also of interest App::Pod2Epub

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

      Thanks!

      To be honest, yes i can make something work I was just hoping that someone already did and i was just looking at an old repository instead of the current one or something.

      I already tried a couple of online converters. And the result is crap, to put it mildly.

      Disclaimer: I can neither confirm nor deny that i, as a webdev, have the required skills to fiddle with HTML ;-)

      PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
      Also check out my sisters artwork and my weekly webcomics
        See Re^2: PDL Book as epub? (POD source).

        You can even adjust the make_book.pl script to use a larger font in PDF

        > I was just hoping that someone already did

        I know that feeling, especially after waking up and seeing the pile of dishes in the kitchen... (Again!)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        I've never actually used ePub or one of those new-fangled Kindle etc thingies. Could you try the PDL website's copy (as of a few minutes ago) of the entire book as a large web page, and see if that is a sufficient solution to your problem?

        Otherwise, I'll be extremely grateful if you can have a go with the pod2latex etc stuff suggested elsewhere here and put somewhere here the commands to make such an ePub, and I'll be pleased to generate it and link on the website also.

      Warning: the specific link you give there is now gone, because the whole book is now a single web page on the site.
Re: PDL Book as epub?
by haj (Vicar) on Aug 09, 2024 at 18:07 UTC

    Not directly answering the question, but I consider this relevant for learning PDL: I found the shell pdl2 incredibly useful. PDL is a bit special because it imports lot of stuff into your namespace, but for interactive use this is exactly what you want. The demo command of this shell is amazing. I use pdl2 a lot to check whether I understood the docs correctly. Also, it is very easy to visualize data sets by drawing them interactively in 2D and 3D.

      I've never really got into using the pdl2 shell; I find perldl works great for me.

      The PDL website at https://pdl.perl.org/ had the first chapter (only) of The Book linked from the left sidebar. Had, you say? Yes. Now the same link is to the entire thing in one (somewhat large) web page. Comments welcome.

Re: PDL Book as epub?
by karlgoethebier (Abbot) on Aug 09, 2024 at 12:35 UTC
Re: PDL Book as epub?
by perlfan (Parson) on Aug 24, 2024 at 17:28 UTC
    Calibre is a full, local e-book management system that can convert from PDF to various mobile formats to get it on your Kindle or whatever. YMMV.
Re: PDL Book as epub?
by cavac (Prior) on Oct 18, 2024 at 10:20 UTC

    Newest version (2024-10-18), this now includes the source code file from the "Graphics with PLplot" chapter into the epub.

    #!/usr/bin/env perl use v5.36; use strict; use warnings; use Carp; use App::Pod2Epub; #use Archive::Zip; use GD; use MIME::Base64; use English; my $parser = App::Pod2Epub->new(); my @full; my @subfiles; { # Read and parse TOC pod my @lines = _readFile('PDL/Book.pod'); my $istoc = 0; foreach my $line (@lines) { if($line =~ /^\=over/) { $istoc = 1; #push @full, $line; next; } elsif($line =~ /^\=back/) { $istoc = 0; #push @full, $line; next; } elsif($istoc && $line =~ /^\=item/) { my $subfile = ''; if($line =~ /\<(.+?)\|/) { $subfile = $1; $line =~ s/.*\>\ //; $subfile =~ s/\:\:/\//g; #next if($subfile =~ /PLplot/); $subfile .= '.pod'; if(!-f $subfile) { warn("$subfile does not exist"); next; } else { push @subfiles, $subfile; } } push @full, $line; next; } push @full, $line; } push @full, ''; } { # Process chapters foreach my $subfile (@subfiles) { my @lines = _readFile($subfile); foreach my $line (@lines) { if($line =~ /^\=for\ html/) { if($line =~ /\<img.*src\=\"(.+?)\"/) { my $img = 'PDL/Book/' . $1; if(-f $img) { my $imgdata = _slurpBinFile($img); $imgdata = encode_base64($imgdata, ''); my $imggd = GD::Image->new($img); my ($width, $height) = $imggd->getBounds(); my $realline = '=for html <img width="' . $wid +th . '" height="' . $height . '" src="data:image/png;base64, ' . $img +data . '"/>'; push @full, $realline; } else { warn("Missing image $img in file $subfile"); push @full, "Missing image: $img"; } next; } elsif($line =~ /\<a.*href\=\"(.+?)\"/) { my $rawfname = $1; my $fnameonly = '' . $rawfname; $fnameonly =~ s/^.*\///g; my $pathonly = '' . $rawfname; $pathonly =~ s/\/(.+?)$//g; push @full, ''; push @full, '=head4 Source code ' . $fnameonly; push @full, ''; my $realpath = 'PDL/Book/' . $pathonly . '/work/' +. $fnameonly; open(my $srcfh, '<', $realpath) or croak("File not + found: $realpath"); while((my $srcline = <$srcfh>)) { chomp $srcline; push @full, ' ' . $srcline; } close $srcfh; push @full, ''; push @full, '=over'; push @full, ''; next; } else { warn("Unknown 'for html' tag: $line in $subfile"); next; } } push @full, $line; } push @full, ''; } } { # Write complete POD file open(my $ofh, '>', 'complete_book.pod') or croak($!); foreach my $line (@full) { print $ofh $line, "\n"; } close $ofh; } if(0){ # Convert file to epub open(my $ifh, '<', 'complete_book.pod') or croak($!); open(my $ofh, '>', 'complete_book.epub') or croak($!); binmode $ofh; $parser->output_fh($ofh); $parser->parse_file($ifh); close $ifh; close $ofh; } `pod2epub complete_book.pod -o complete_book.epub`; #{ # Add images to ZIP file # my $zip = Archive::Zip->new('complete_book.epub'); # foreach my $img (@images) { # $zip->addFile('PDL/Book/' . $img => $img); # } # $zip->overwrite(); #} sub _readFile($fname) { my @lines; open(my $ifh, '<', $fname) or croak($!); while((my $line = <$ifh>)) { chomp $line; push @lines, $line; } close $ifh; return @lines; } sub _slurpBinFile($fname) { # Read in file in binary mode, slurping it into a single scalar. # We have to make sure we use binmode *and* turn off the line term +ination variable completly # to work around the multiple idiosynchrasies of Perl on Windows open(my $fh, "<", $fname) or croak("$ERRNO"); local $INPUT_RECORD_SEPARATOR = undef; binmode($fh); my $data = <$fh>; close($fh); return $data; }

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics