latex_formula_converter 0.1.0

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: 686bde7a1fbbb982cbad342458701ee8571a338e
4
+ data.tar.gz: 0501fe4d2d915aa53f96056dd29ccab7e4e1eb0f
5
+ SHA512:
6
+ metadata.gz: db6cd8b908596c36d0ea75fa3c3fbcd5ecfaf8b950cfcac2f2d7bdbcccbeaf61ac695adac97cd1f939af7418ad69a3e5064a1a2b5a6671c7e74bc242341937cf
7
+ data.tar.gz: a4b6cd063b21b7b6b90e105fe7f0e4e1c24da43a5ee4c362756ef324125aeae54c507b658e4618ed634e44093df9989c4f13c74182459a871c96b13536469d20
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ output.pdf
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Metrics/MethodLength:
8
+ Max: 30
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Style/GuardClause:
17
+ Enabled: false
18
+
19
+ Style/HashSyntax:
20
+ Exclude:
21
+ - 'Rakefile'
22
+
23
+ Style/IfUnlessModifier:
24
+ Enabled: false
25
+
26
+ Style/PercentLiteralDelimiters:
27
+ PreferredDelimiters:
28
+ '%w': '[]'
29
+ '%i': '[]'
30
+
31
+ Style/StringLiterals:
32
+ Enabled: false
33
+
34
+ Style/TrailingCommaInArguments:
35
+ Enabled: false
36
+
37
+ Style/TrailingCommaInLiteral:
38
+ Enabled: false
39
+
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install:
6
+ - gem update --system
7
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in latex_formula_converter.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # LatexFormulaConverter
2
+ simple command line tool for mathematical formula of latex
3
+
4
+ ## [wip] Installation
5
+ *please exec `git clone` if you want to use this tool because this library is not released yet*
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'latex_formula_converter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install latex_formula_converter
20
+
21
+ ## Requirement
22
+ - platex
23
+ - dvipdfmx
24
+ - imagemagick (if you want to convert from pdf to image)
25
+ - with ghostscript
26
+
27
+ ## Usage
28
+
29
+ ```sh
30
+ $ lfconvert "your mathematical formula"
31
+ ```
32
+ e.g.
33
+ ```sh
34
+ $ lfconvert "\sum_{i=1}^{\infty} \frac{1}{i^2}"
35
+ ```
36
+
37
+ ## TODO
38
+ - [x] fix adjustment of generated pdf's blank
39
+ - [ ] fix `\\`'s handling. (Now, if you want to break line, you need to input `\\\\` istead of `\\`)
40
+ - [ ] activate some options
41
+ - [ ] select output file type
42
+ - [x] determine output file name
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/naoki-k/latex_formula_converter.
47
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "latex_formula_converter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/lfconvert ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+ require 'latex_formula_converter'
5
+
6
+ LatexFormulaConverter::CLI.start(ARGV)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'latex_formula_converter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "latex_formula_converter"
8
+ spec.version = LatexFormulaConverter::VERSION
9
+ spec.authors = ["Naoki Kanatani"]
10
+ spec.email = ["k12naoki@gmail.com"]
11
+
12
+ spec.summary = "Command Line Tool for conversion of mathematical formula written by LaTeX Edit"
13
+ spec.description = "Command Line Tool for conversion of mathematical formula written by LaTeX Edit"
14
+ spec.homepage = "https://github.com/naoki-k/latex_formula_converter"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rubocop"
25
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ require 'optparse'
3
+
4
+ module LatexFormulaConverter
5
+ class CLI
6
+ class << self
7
+ def start(argv)
8
+ new(argv).run
9
+ end
10
+ end
11
+
12
+ def initialize(argv)
13
+ @argv = argv
14
+ parser.order!(@argv)
15
+ end
16
+
17
+ def run
18
+ parser.parse!
19
+
20
+ if @help || @argv.empty?
21
+ puts parser.help
22
+ exit
23
+ end
24
+
25
+ LatexFormulaConverter::Conversion.new(@argv.shift).call(name)
26
+
27
+ # TODO: convert #{name}.pdf #{name}.#{format}
28
+ end
29
+
30
+ private
31
+
32
+ def format
33
+ @format ||= "pdf"
34
+ end
35
+
36
+ def name
37
+ @name ||= "output-#{Time.now.to_i}"
38
+ end
39
+
40
+ def parser
41
+ @parser ||= OptionParser.new do |opt|
42
+ opt.on('-h', '--help', 'show help') { @help = true }
43
+ opt.on('-f', '--format EXT', 'format of output file') { |v| @format = v unless v.empty? }
44
+ opt.on('-n', '--name NAME', 'name of output file') { |v| @name = v unless v.empty? }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+ require 'tempfile'
3
+ require 'tmpdir'
4
+ require 'open3'
5
+
6
+ module LatexFormulaConverter
7
+ class Conversion
8
+ def initialize(statement)
9
+ @dir = Dir.mktmpdir("latex-conversion")
10
+ @tmp = Tempfile.new(['math-', '.tex'], @dir)
11
+ @tmp.puts(template_with(statement))
12
+ @tmp.rewind
13
+ end
14
+
15
+ def call(name)
16
+ platex
17
+ dvipdfmx(name)
18
+ remove_tmp_dir
19
+ end
20
+
21
+ private
22
+
23
+ def platex
24
+ unless Open3.capture3('which', 'platex').last.success?
25
+ remove_tmp_dir
26
+ abort 'platex not found.'
27
+ end
28
+
29
+ stdout, _, status = Open3.capture3('platex', "-output-directory=#{@dir}", @tmp.path)
30
+
31
+ if status.success?
32
+ puts "[success] generated dvi file"
33
+ else
34
+ remove_tmp_dir
35
+ abort "[failed]\n#{stdout}"
36
+ end
37
+ end
38
+
39
+ def dvipdfmx(name)
40
+ unless Open3.capture3('which', 'dvipdfmx').last.success?
41
+ remove_tmp_dir
42
+ abort 'dvipdfmx not found.'
43
+ end
44
+
45
+ stdout, _, status =
46
+ Open3.capture3('dvipdfmx', '-o', "#{name}.pdf",
47
+ "#{File.dirname(@tmp.path)}/#{File.basename(@tmp.path, '.tex')}.dvi")
48
+
49
+ if status.success?
50
+ puts "[success] generated pdf file"
51
+ else
52
+ remove_tmp_dir
53
+ abort "[failed]\n#{stdout}"
54
+ end
55
+ end
56
+
57
+ def remove_tmp_dir
58
+ FileUtils.rm_r(@dir)
59
+ end
60
+
61
+ def template_with(statement)
62
+ <<~TEX
63
+ \\documentclass[margin=0.1cm]{standalone}
64
+ \\usepackage{amsmath,amssymb}
65
+ \\usepackage{latexsym}
66
+ \\usepackage[dvipdfmx]{graphicx}
67
+ \\begin{document}
68
+ $
69
+ \\begin{aligned}
70
+ #{statement}
71
+ \\end{aligned}
72
+ $
73
+ \\end{document}
74
+ TEX
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module LatexFormulaConverter
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,3 @@
1
+ require "latex_formula_converter/version"
2
+ require "latex_formula_converter/cli"
3
+ require "latex_formula_converter/conversion"
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: latex_formula_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naoki Kanatani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-15 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Command Line Tool for conversion of mathematical formula written by LaTeX
70
+ Edit
71
+ email:
72
+ - k12naoki@gmail.com
73
+ executables:
74
+ - lfconvert
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/lfconvert
88
+ - latex_formula_converter.gemspec
89
+ - lib/latex_formula_converter.rb
90
+ - lib/latex_formula_converter/cli.rb
91
+ - lib/latex_formula_converter/conversion.rb
92
+ - lib/latex_formula_converter/version.rb
93
+ homepage: https://github.com/naoki-k/latex_formula_converter
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.10
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Command Line Tool for conversion of mathematical formula written by LaTeX
116
+ Edit
117
+ test_files: []