mdtex 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 093085c935da9524018884975a02cb21f26d5ee9
4
+ data.tar.gz: 460c04930e13ff510ad36f97082aa9ca00cf3d52
5
+ SHA512:
6
+ metadata.gz: c1e6c6822cf0966d233fbba05d20f4b24993d11a6a73696d394836d795f65380d40eed160b91e1770bdf97bc38c629bc21554d99c5e3bbe4f4298c7fcc2a720e
7
+ data.tar.gz: 51a9fbb06f040d4ff42688cc8ec55afe5b94d5483070258f520cfac6d5c41a7b4f2043e2e63af3417d21d9ae412b6737c9d735a2164dface02cae923d4564e35
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ vendor/bundle
20
+ .*.swp
21
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mdtex.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 izumin5210
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # mdTeX
2
+
3
+ This gem provides some functions making LaTeX document with Markdown.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'mdtex'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install mdtex
19
+
20
+
21
+ ## Usage
22
+
23
+ ### Create a new LaTeX document
24
+
25
+ ```
26
+ $ mdtex init mydocument
27
+ $ cd mydocument
28
+ ```
29
+
30
+ where "mydocument" is the document name.
31
+
32
+
33
+ ### Build your document
34
+
35
+ ```
36
+ $ rake build
37
+ ```
38
+
39
+
40
+ ## Directory Structure
41
+
42
+ ```
43
+
44
+ |- src: Source directory
45
+ | |- document.tex: Root document
46
+ | |- foo.md
47
+ | |- bar.md
48
+ | ...
49
+ |
50
+ |- tmp
51
+ |- dist
52
+ |- Rakefile
53
+ |- settings.yml: Setting file
54
+ ```
55
+
56
+
57
+ ## Contributing
58
+
59
+ * izumin5210 ([Twitter](http://twitter.com/izumin5210/), [GitHub](http://github.com/izumin5210/))
60
+
61
+ 1. Fork it ( http://github.com/izumin5210/mdtex/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
66
+
67
+
68
+ ## License
69
+
70
+ mdTeX is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :debug_install do
4
+ gem = $1 if `bundle exec rake build` =~ /(pkg\/mdtex-[\d\.]+\.gem)\.$/
5
+ sh "gem install -l #{gem}"
6
+ sh "rbenv rehash"
7
+ end
data/bin/mdtex ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:<< File.join(File.dirname(__FILE__), "../lib")
3
+
4
+ require 'mdtex/cli'
5
+ Mdtex::CLI.start
data/lib/mdtex/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'thor'
2
+
3
+ module Mdtex
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
9
+ end
10
+
11
+ desc "init", "Create a new TeX project."
12
+ def init(name)
13
+ templates = {
14
+ "gitignore.tt" => ".gitignore",
15
+ "Rakefile.tt" => "Rakefile",
16
+ "config.yml.tt" => "config.yml",
17
+ "src/document.tex.tt" => "src/document.tex"
18
+ }
19
+
20
+ templates.each do |src, dist|
21
+ template(src, "#{name}/#{dist}")
22
+ end
23
+
24
+ Dir.chdir(name) { `git init; git add .` }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'yaml'
2
+ require 'rake'
3
+
4
+ module Mdtex
5
+ module Constant
6
+ config = YAML.load_file(Mdtex::SETTING_FILE)
7
+ CWD = Dir.pwd
8
+
9
+ # config (flag)
10
+ DO_BIBTEX = config['bibtex'].freeze
11
+
12
+ # config (command)
13
+ TEX2DVI_COMMAND = config['command']['tex2dvi'].freeze
14
+ DVI2PDF_COMMAND = config['command']['dvi2pdf'].freeze
15
+ BIBTEX_COMMAND = config['command']['bibtex'].freeze
16
+ PREVIEW_COMMAND = config['command']['preview'].freeze
17
+
18
+ # config (file, directory)
19
+ SRC_DIR = File.join(CWD, config['src']).freeze
20
+ TEMP_DIR = File.join(CWD, config['temp']).freeze
21
+ DEST_DIR = File.join(CWD, config['dest']).freeze
22
+ ROOT_FILE = config['root_file'].freeze
23
+
24
+ # src files
25
+ MD_FILES = FileList["#{SRC_DIR}/**/*.md"]
26
+ SRC_FILES = FileList.new("#{SRC_DIR}/**/*") do |list|
27
+ list.exclude('**/*.md')
28
+ list.exclude { |f| File.directory? f }
29
+ end
30
+
31
+ # generated files
32
+ TEX_FILES = MD_FILES.gsub(/^#{SRC_DIR}/, TEMP_DIR).ext('.tex')
33
+ MISC_FILES = SRC_FILES.gsub(/^#{SRC_DIR}/, TEMP_DIR)
34
+ DVI_FILE = ROOT_FILE.ext('.dvi').freeze
35
+ AUX_FILE = ROOT_FILE.ext('.aux').freeze
36
+ PDF_FILE = ROOT_FILE.ext('.pdf').freeze
37
+ end
38
+ end
@@ -0,0 +1,51 @@
1
+ include Mdtex::load_config
2
+
3
+ verbose false
4
+
5
+ directory TEMP_DIR
6
+ directory DEST_DIR
7
+ desc "Build #{PDF_FILE} into #{File.basename(DEST_DIR)}"
8
+ task build: File.join(DEST_DIR, PDF_FILE)
9
+
10
+ # Copy SRC_DIR/* (exclude *.md) to TEMP_DIR
11
+ rule %r{^#{TEMP_DIR}/(?!.+\.md$)} => "%{^#{TEMP_DIR},#{SRC_DIR}}p" do |task|
12
+ Mdtex::make_target_directory(task.name)
13
+ puts "copy #{Mdtex.relative_path(task.source)} => #{Mdtex.relative_path(task.name)}"
14
+ cp_r task.source, task.name
15
+ end
16
+
17
+ # Convert SRC_DIR/*.md to TEMP_DIR/*.tex"
18
+ rule %r{#{TEMP_DIR}/.+\.tex} => "%{^#{TEMP_DIR},#{SRC_DIR}}X.md" do |task|
19
+ Mdtex::make_target_directory(task.name)
20
+ puts "convert #{Mdtex.relative_path(task.source)} => #{Mdtex.relative_path(task.name)}"
21
+ Mdtex::md2latex(task.source, task.name)
22
+ end
23
+
24
+ # Build DVI_FILE from ROOT_FILE into TEMP_DIR
25
+ file File.join(TEMP_DIR, DVI_FILE) => [TEMP_DIR, TEX_FILES, MISC_FILES].flatten do |task|
26
+ puts "build #{File.basename(task.name)}"
27
+ cd TEMP_DIR do
28
+ sh "#{TEX2DVI_COMMAND} #{ROOT_FILE} > /dev/null"
29
+ if DO_BIBTEX
30
+ sh "#{BIBTEX_COMMAND} #{AUX_FILE} > /dev/null"
31
+ sh "#{TEX2DVI_COMMAND} #{ROOT_FILE} > /dev/null"
32
+ end
33
+ end
34
+ end
35
+
36
+ # Build PDF_FILE from DVI_FILE into TEMP_DIR
37
+ file File.join(TEMP_DIR, PDF_FILE) => File.join(TEMP_DIR, DVI_FILE) do |task|
38
+ puts "build #{File.basename(task.name)}"
39
+ cd TEMP_DIR do
40
+ stderr = capture(:stderr) { sh "#{DVI2PDF_COMMAND} #{DVI_FILE}" }
41
+ # get file size and number of pages from stderr of dvipdfmx
42
+ if stderr.split("\n")[1] =~ /\[(\d+)\]$/
43
+ puts "#{$1} page#{$1.to_i > 1 ? 's' : ''}, #{stderr.split("\n")[2]}"
44
+ end
45
+ end
46
+ end
47
+
48
+ # Copy PDF_FILE to DEST_DIR
49
+ file File.join(DEST_DIR, PDF_FILE) => File.join(TEMP_DIR, PDF_FILE) do |task|
50
+ cp task.prerequisites[0], DEST_DIR
51
+ end
@@ -0,0 +1,11 @@
1
+ require 'rake/clean'
2
+
3
+ include Mdtex::load_config
4
+
5
+ CLEAN.include(FileList["#{TEMP_DIR}/*"])
6
+ CLEAN.include(FileList["#{DEST_DIR}/*"])
7
+
8
+ desc "Preview #{File.join(File.basename(TEMP_DIR), PDF_FILE)} with #{PREVIEW_COMMAND}"
9
+ task :preview do
10
+ sh "#{PREVIEW_COMMAND} #{File.join(TEMP_DIR, PDF_FILE)}"
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'mdtex'
2
+
@@ -0,0 +1,11 @@
1
+ src: src
2
+ temp: tmp
3
+ dest: dist
4
+ images: images
5
+ root_file: document.tex
6
+ command:
7
+ tex2dvi: 'platex -synctex=1 -interaction=nonstopmode -file-line-error-style -shell-escape'
8
+ dvi2pdf: 'dvipdfmx -d 5'
9
+ bibtex: 'pbibtex'
10
+ preview: '/usr/bin/open -a TeXShop.app'
11
+ bibtex: false
@@ -0,0 +1,131 @@
1
+ # from https://github.com/github/gitignore/blob/master/TeX.gitignore
2
+ #
3
+ # Copyright (c) 2014 GitHub, Inc.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a
6
+ # copy of this software and associated documentation files (the "Software"),
7
+ # to deal in the Software without restriction, including without limitation
8
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ # and/or sell copies of the Software, and to permit persons to whom the
10
+ # Software is furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+ #
23
+
24
+ ## Core latex/pdflatex auxiliary files:
25
+ *.aux
26
+ *.lof
27
+ *.log
28
+ *.lot
29
+ *.fls
30
+ *.out
31
+ *.toc
32
+
33
+ ## Intermediate documents:
34
+ *.dvi
35
+ # these rules might exclude image files for figures etc.
36
+ # *.ps
37
+ # *.eps
38
+ # *.pdf
39
+
40
+ ## Bibliography auxiliary files (bibtex/biblatex/biber):
41
+ *.bbl
42
+ *.bcf
43
+ *.blg
44
+ *-blx.aux
45
+ *-blx.bib
46
+ *.run.xml
47
+
48
+ ## Build tool auxiliary files:
49
+ *.fdb_latexmk
50
+ *.synctex.gz
51
+ *.synctex.gz(busy)
52
+ *.pdfsync
53
+
54
+ ## Auxiliary and intermediate files from other packages:
55
+
56
+ # algorithms
57
+ *.alg
58
+ *.loa
59
+
60
+ # amsthm
61
+ *.thm
62
+
63
+ # beamer
64
+ *.nav
65
+ *.snm
66
+ *.vrb
67
+
68
+ #(e)ledmac/(e)ledpar
69
+ *.end
70
+ *.[1-9]
71
+ *.[1-9][0-9]
72
+ *.[1-9][0-9][0-9]
73
+ *.[1-9]R
74
+ *.[1-9][0-9]R
75
+ *.[1-9][0-9][0-9]R
76
+
77
+ # glossaries
78
+ *.acn
79
+ *.acr
80
+ *.glg
81
+ *.glo
82
+ *.gls
83
+
84
+ # hyperref
85
+ *.brf
86
+
87
+ # listings
88
+ *.lol
89
+
90
+ # makeidx
91
+ *.idx
92
+ *.ilg
93
+ *.ind
94
+ *.ist
95
+
96
+ # minitoc
97
+ *.maf
98
+ *.mtc
99
+ *.mtc0
100
+
101
+ # minted
102
+ *.pyg
103
+
104
+ # nomencl
105
+ *.nlo
106
+
107
+ # sagetex
108
+ *.sagetex.sage
109
+ *.sagetex.py
110
+ *.sagetex.scmd
111
+
112
+ # sympy
113
+ *.sout
114
+ *.sympy
115
+ sympy-plots-for-*.tex/
116
+
117
+ # todonotes
118
+ *.tdo
119
+
120
+ # xindy
121
+ *.xdy
122
+
123
+ # ruby
124
+ vendor/bundle
125
+ .bundle
126
+
127
+ # misc
128
+ .DS_Store
129
+ !tmp/document.pdf
130
+ tmp
131
+
File without changes
data/lib/mdtex/util.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'pathname'
2
+
3
+ module Mdtex
4
+ SETTING_FILE = './config.yml'
5
+ class << self
6
+ def load_config
7
+ raise 'config.yml is not found.' unless File.exists? SETTING_FILE
8
+ require 'mdtex/constant'
9
+ Mdtex::Constant
10
+ end
11
+
12
+ def make_target_directory(target)
13
+ target_dir = File.dirname(target)
14
+ FileUtils.mkdir_p target_dir unless File.directory?(target_dir)
15
+ end
16
+
17
+ def md2latex(src, dest)
18
+ if exist_command?('pandoc')
19
+ `pandoc #{src} -o #{dest} > /dev/null`
20
+ else
21
+ raise 'pandoc is not installed.'
22
+ end
23
+ end
24
+
25
+ def exist_command?(command)
26
+ `type "#{command}" 2> /dev/null` != ''
27
+ end
28
+
29
+ def relative_path(path, base=Dir.pwd)
30
+ Pathname(path).relative_path_from(Pathname(base))
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Mdtex
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mdtex.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'mdtex/version'
2
+ require 'mdtex/util'
3
+ require 'capture_std'
4
+
5
+ module Mdtex
6
+ end
7
+
8
+ Dir[File.join(File.dirname(__FILE__), 'mdtex/tasks', '**/*.rake')].each { |rake| load rake }
data/mdtex.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mdtex/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mdtex"
8
+ spec.version = Mdtex::VERSION
9
+ spec.authors = ["izumin5210"]
10
+ spec.email = ["masayuki@izumin.info"]
11
+ spec.summary = %q{Make LaTeX document with Markdown}
12
+ spec.description = %q{This gem provides some functions making LaTeX document with Markdown.}
13
+ spec.homepage = "http://izumin.info/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "thor"
24
+ spec.add_runtime_dependency "capture_std"
25
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdtex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - izumin5210
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capture_std
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This gem provides some functions making LaTeX document with Markdown.
70
+ email:
71
+ - masayuki@izumin.info
72
+ executables:
73
+ - mdtex
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/mdtex
83
+ - lib/mdtex.rb
84
+ - lib/mdtex/cli.rb
85
+ - lib/mdtex/constant.rb
86
+ - lib/mdtex/tasks/build.rake
87
+ - lib/mdtex/tasks/misc.rake
88
+ - lib/mdtex/templates/Rakefile.tt
89
+ - lib/mdtex/templates/config.yml.tt
90
+ - lib/mdtex/templates/gitignore.tt
91
+ - lib/mdtex/templates/src/document.tex.tt
92
+ - lib/mdtex/util.rb
93
+ - lib/mdtex/version.rb
94
+ - mdtex.gemspec
95
+ homepage: http://izumin.info/
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Make LaTeX document with Markdown
119
+ test_files: []
120
+ has_rdoc: