Skip to content

Commit

Permalink
Simplify and code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Nott <matthias.nott@sap.com>
  • Loading branch information
mnottsap committed Jan 5, 2017
1 parent 9182839 commit dfc74ef
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 74 deletions.
5 changes: 2 additions & 3 deletions .includepath
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<includepath>
<includepathentry path="/pgm/perl/workspace/.metadata/.plugins/org.epic.debug" />
<includepathentry path="/opt/local/lib/perl5/site_perl/5.24" />
<includepathentry path="/opt/local/lib/perl5/vendor_perl/5.24" />
<includepathentry path="/opt/local/lib/perl5/5.24" />
<includepathentry path="." />
<includepathentry path="./lib" />
<includepathentry path="/Users/mnott/perl5/perlbrew/perls/perl-5.24.0" />
</includepath>

53 changes: 38 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# NAME

TeXDown - Markdown for LaTeX and Instrument Scrivener

# VERSION

Version 0.0.1

# LICENCE AND COPYRIGHT
Copyright (c) 2016 Matthias Nott (mnott (at) mnsoft.org).

Licensed under WTFPL.

# DEPENDENCIES

# NAME

TeXDown - Use Markdown with LaTeX, and particularly with Scrivener.

The program was written for two reasons:
Expand Down Expand Up @@ -46,7 +61,7 @@ Command line parameters can take any order on the command line.

-help brief help message (alternatives: ?, -h)
-man full documentation (alternatives: -m)
-v verbose (alternatives: -d, -debug, -verbose)
-d debug (alternatives: -debug)
-n do not actually parse Markdown into LaTeX
(alternative: -no, -nothing)

Expand Down Expand Up @@ -80,6 +95,15 @@ Command line parameters can take any order on the command line.

Prints the manual page and exits.

- **-d**

Print debug information to stderr. You can set the log level as
any of OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL. If you
don't specify a log level, DEBUG is used. If you don't use the
parameter, whatever is specified in log4p.ini is used (probably
WARN, but of course you can change that). The more
you go from OFF to ALL, the more information you will get.

- **-v**

Put LaTeX comments into the output with the name of the file that
Expand Down Expand Up @@ -144,20 +168,20 @@ Command line parameters can take any order on the command line.
- **-a**

Disrespect the Scrivener metadata field IncludeInCompilation, which
can be set from Scrivener. By default, we respect this metadata
can be set from Scrivener. By default, we respect this metadata
field. Since it can be set at every level, if
we detect it to be unset at level n in the document tree, we will
not follow down into the children of that tree, even if they have
it set. This allows us to easily exclude whole trees of content
it set. This allows us to easily exclude whole trees of content
from the compilation - except if we chose to include all nodes
using the -a switch.

- **-l**

Rather than actually printing the parsed content, only print
the document IDs and titles that would have been included.
the document IDs and titles that would have been included.

Those document IDs correspond to RTF files which you would find
Those document IDs correspond to RTF files which you would find
in the Files/Docs subdirectory; hence this option might be useful
for you to understand which file corresponds to which Scrivener object.

Expand All @@ -172,14 +196,14 @@ Command line parameters can take any order on the command line.
; TeXDown Configuration File
;
[GLOBAL]

[Dissertation]
p=Dissertation

[rd]
; Research Design
p=/LaTeX/Article/Frontmatter, "Research Design", /LaTeX/Article/Backmatter

[roilr]
; ROI - Literature Review
p=/LaTeX/Article/Frontmatter, "ROI - Literature Review", /LaTeX/Article/Backmatter
Expand Down Expand Up @@ -357,7 +381,6 @@ on your system are listed at the top of **texdown.pl**:
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use Data::Dumper;
use RTF::TEXT::Converter;
use XML::LibXML;
use Tie::IxHash;
Expand Down Expand Up @@ -429,7 +452,7 @@ the disk. Scrivener holds its files in a directory like

So what **TeXDown** will do is that it will first detect whether
a file given on the command line is actually a Scrivener database,
then it will try to locate the **.scrivx** file within that, to
then it will try to locate the **.scrivx** file within that, to
then parse it in order to find out the root folder that you wanted
the processing to start at. It will then, one after another,
try to locate the related rtf files, convert them to plain text,
Expand Down Expand Up @@ -514,7 +537,7 @@ becomes:

\\part{This is a part}\\label{This-is-a-part}

Likewise, for
Likewise, for

\## Section

Expand Down Expand Up @@ -587,7 +610,7 @@ Citations are the strongest part of using Markdown over LaTeX.
Consider this scenario:

\citeauthor{Nott:2016} wrote about Markdown, that ``citations
are the strongest part of using Markdown over LaTeX.''
are the strongest part of using Markdown over LaTeX.''
(\citeyear[20-30]{Nott:2016}) He also holds that using a simple
Perl script, you can \emph{very much} simplify the problem
\citep[ibd.]{Nott:2016}.
Expand Down Expand Up @@ -637,7 +660,7 @@ it using "year, parenthesis."

#### Simple Page Ranges

If you want to add page ranges to it, you add those in
If you want to add page ranges to it, you add those in
round parentheses, to any of the above forms. So for example:

(20-30)[yp#Nott:2016] => (\citeyear[20-30]{Nott:2016})
Expand Down Expand Up @@ -685,14 +708,14 @@ Finally, for emphasizing things, you can do this:

Let's do a crazy thing: Use a two line **TeXDown** file:

(As \[a#Nott:2016\] said, "TeXdown is quite easy."
(As \[a#Nott:2016\] said, "TeXdown is quite easy."
(20)\[yp#Nott:2002\])\_\_\[a#Nott:2005\] had \*\*already\*\* said: "This is the \*\*right\*\* thing to do" (20--23, \*\*emphasis\*\* ours)\[ypi#Nott:2016\]\_\_\_\_Debatable.\_\_

and parse it by **TeXDown**;

cat crazy.tex | ./texdown.pl

(As \\citeauthor{Nott:2016} said, \`\`TeXdown is quite easy.''
(As \\citeauthor{Nott:2016} said, \`\`TeXdown is quite easy.''
(\\citeyear\[20\]{Nott:2002}))\\footnote{\\citeauthor{Nott:2005} had \\emph{already} said: \`\`This is the \\emph{right} thing to do'' (20--23, \\emph{emphasis} ours)(\\citeyear\[ibd.\]{Nott:2016})}\\footnote{Debatable.}

Agreed, both are probably not all that readable, but it makes
Expand Down
34 changes: 15 additions & 19 deletions lib/TeXDown/TConfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ $cfg->load($INI);


has cfg_of => (
is => 'ro',
is => 'rw',
traits => ['Hash'],
isa => 'HashRef',
lazy => 0,
Expand All @@ -162,11 +162,7 @@ has cfg_of => (

sub BUILD {
my ( $self, $arg_ref ) = @_;

# If we have been given an ini file, we load it immediately
if ( exists $arg_ref->{ini} ) {
$self->load( $arg_ref->{ini} );
}
$self->cfg_of($arg_ref->{cfg}) if exists $arg_ref->{cfg};
}


Expand Down Expand Up @@ -357,7 +353,7 @@ Example:

sub set {
my ( $self, $var, $val, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( "$var = " . $self->t_as_string($val) );

Expand Down Expand Up @@ -905,7 +901,7 @@ Example:
#
sub append {
my ( $self, $var, $val, $as, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace(
"$var = " . $self->t_as_string( $val, $as, $arg_ref ) );
Expand Down Expand Up @@ -1056,7 +1052,7 @@ Example:

sub get {
my ( $self, $var, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

my $log = "$var " . $self->t_as_string($arg_ref) . ": ";

Expand Down Expand Up @@ -1200,7 +1196,7 @@ Example:

sub clear {
my ( $self, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( "Clearing " . $self->t_as_string($arg_ref) );

Expand Down Expand Up @@ -1269,7 +1265,7 @@ Example:

sub key_set {
my ( $self, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( $self->t_as_string( keys %$cfg, $arg_ref ) );

Expand Down Expand Up @@ -1307,7 +1303,7 @@ Example:

sub contains_key {
my ( $self, $var, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

my $res = exists $cfg->{$var};

Expand Down Expand Up @@ -1354,7 +1350,7 @@ Example:

sub remove {
my ( $self, $var, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( $self->t_as_string( $var, $arg_ref ) );

Expand Down Expand Up @@ -1393,7 +1389,7 @@ Example:

sub size {
my ( $self, $var, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

my $size = keys %$cfg;

Expand Down Expand Up @@ -1429,7 +1425,7 @@ Example:

sub is_empty {
my ( $self, $var, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( "+ " . ( 0 == keys %$cfg ) );

Expand Down Expand Up @@ -1468,7 +1464,7 @@ Example:

sub add_all {
my ( $self, $var, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( $self->t_as_string( $var, $arg_ref ) );

Expand Down Expand Up @@ -1695,7 +1691,7 @@ and you'd have:

sub load {
my ( $self, $ini, $arg_ref ) = @_;
my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

$self->log->trace( "> " . "-" x 40 );

Expand Down Expand Up @@ -1829,13 +1825,13 @@ sub load {
sub describe {
my ($self) = @_;

return $self->{cfg_of};
return $self->cfg_of;
}

sub dump {
my ($self) = @_;
$Data::Dumper::Terse = 1;
$self->log->trace( sub { Data::Dumper::Dumper( $self->describe() ) } );
$self->log->trace( sub { Data::Dumper::Dumper( $self->describe ) } );
}


Expand Down
15 changes: 5 additions & 10 deletions lib/TeXDown/TFileResolver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ my $resolver = TeXDown::TFileResolver->new ( cfg => $cfg );


has cfg_of => (
is => 'ro',
is => 'rw',
isa => 'TeXDown::TConfig',
lazy => 0,
);
Expand All @@ -148,12 +148,7 @@ has cfg_of => (

sub BUILD {
my ( $self, $arg_ref ) = @_;

# If we have been given an configuration object, we make it
# available
if ( exists $arg_ref->{cfg} ) {
$self->{cfg_of} = $arg_ref->{cfg};
}
$self->cfg_of($arg_ref->{cfg}) if exists $arg_ref->{cfg};
}


Expand Down Expand Up @@ -186,7 +181,7 @@ sub resolve_files {
my ( $self, $arg, $arg_ref ) = @_;
$self->log->trace( $self->t_as_string( $arg, $arg_ref ) );

my $cfg = $self->{cfg_of};
my $cfg = $self->cfg_of;

if ( -e "$arg" || -e "$arg.scriv" ) {
my ( $fname, $fpath, $fsuffix ) = fileparse( $arg, qr/\.[^.]*/ );
Expand Down Expand Up @@ -239,13 +234,13 @@ sub resolve_files {
sub describe {
my ($self) = @_;

return $self->{cfg_of};
return $self->cfg_of;
}

sub dump {
my ($self) = @_;
$Data::Dumper::Terse = 1;
$self->log->trace( sub { Data::Dumper::Dumper( $self->describe() ) } );
$self->log->trace( sub { Data::Dumper::Dumper( $self->describe ) } );
}


Expand Down
Loading

0 comments on commit dfc74ef

Please sign in to comment.