on master help sign in
Initial commit
commit7c954c63efe32364c4346816914c4f128d706687 authorilyakooo0 <ilyakooo0@gmail.com> dateWed 13 Sep 2017, 22:06 (9 years ago) parent0d2020b
7 files changed+461
.gitignore+8 Mathdown/Mathdown.xcodeproj/project.pbxproj+284 Mathdown/Mathdown.xcodeproj/project.xcworkspace/contents.xcworkspacedata+7 Mathdown/Mathdown/main.swift+136 README.md+26 images/mat1.png images/mat2.png
.gitignore+8
@@ -65,3 +65,11 @@ fastlane/report.xml
6565fastlane/Preview.html
6666fastlane/screenshots
6767fastlane/test_output
68+
69+
70+# Custom
71+.DS_Store
72+Source/Application.h
73+*.xcodeproj/*
74+!*.xcodeproj/project.pbxproj
75+!*.xcodeproj/xcshareddata
Mathdown/Mathdown.xcodeproj/project.pbxprojnew file+284
@@ -0,0 +1,284 @@
1+// !$*UTF8*$!
2+{
3+ archiveVersion = 1;
4+ classes = {
5+ };
6+ objectVersion = 48;
7+ objects = {
8+
9+/* Begin PBXBuildFile section */
10+ 09ED4FDB1F6995E200289153 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09ED4FDA1F6995E200289153 /* main.swift */; };
11+/* End PBXBuildFile section */
12+
13+/* Begin PBXCopyFilesBuildPhase section */
14+ 09ED4FD51F6995E200289153 /* CopyFiles */ = {
15+ isa = PBXCopyFilesBuildPhase;
16+ buildActionMask = 2147483647;
17+ dstPath = /usr/share/man/man1/;
18+ dstSubfolderSpec = 0;
19+ files = (
20+ );
21+ runOnlyForDeploymentPostprocessing = 1;
22+ };
23+/* End PBXCopyFilesBuildPhase section */
24+
25+/* Begin PBXFileReference section */
26+ 09ED4FD71F6995E200289153 /* Mathdown */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Mathdown; sourceTree = BUILT_PRODUCTS_DIR; };
27+ 09ED4FDA1F6995E200289153 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
28+ 09ED4FE11F69AD3800289153 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
29+ 09ED4FE21F69B1B300289153 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; name = .gitignore; path = ../.gitignore; sourceTree = "<group>"; };
30+/* End PBXFileReference section */
31+
32+/* Begin PBXFrameworksBuildPhase section */
33+ 09ED4FD41F6995E200289153 /* Frameworks */ = {
34+ isa = PBXFrameworksBuildPhase;
35+ buildActionMask = 2147483647;
36+ files = (
37+ );
38+ runOnlyForDeploymentPostprocessing = 0;
39+ };
40+/* End PBXFrameworksBuildPhase section */
41+
42+/* Begin PBXGroup section */
43+ 09ED4FCE1F6995E200289153 = {
44+ isa = PBXGroup;
45+ children = (
46+ 09ED4FE21F69B1B300289153 /* .gitignore */,
47+ 09ED4FE11F69AD3800289153 /* README.md */,
48+ 09ED4FD91F6995E200289153 /* Mathdown */,
49+ 09ED4FD81F6995E200289153 /* Products */,
50+ );
51+ sourceTree = "<group>";
52+ };
53+ 09ED4FD81F6995E200289153 /* Products */ = {
54+ isa = PBXGroup;
55+ children = (
56+ 09ED4FD71F6995E200289153 /* Mathdown */,
57+ );
58+ name = Products;
59+ sourceTree = "<group>";
60+ };
61+ 09ED4FD91F6995E200289153 /* Mathdown */ = {
62+ isa = PBXGroup;
63+ children = (
64+ 09ED4FDA1F6995E200289153 /* main.swift */,
65+ );
66+ path = Mathdown;
67+ sourceTree = "<group>";
68+ };
69+/* End PBXGroup section */
70+
71+/* Begin PBXNativeTarget section */
72+ 09ED4FD61F6995E200289153 /* Mathdown */ = {
73+ isa = PBXNativeTarget;
74+ buildConfigurationList = 09ED4FDE1F6995E200289153 /* Build configuration list for PBXNativeTarget "Mathdown" */;
75+ buildPhases = (
76+ 09ED4FD31F6995E200289153 /* Sources */,
77+ 09ED4FD41F6995E200289153 /* Frameworks */,
78+ 09ED4FD51F6995E200289153 /* CopyFiles */,
79+ );
80+ buildRules = (
81+ );
82+ dependencies = (
83+ );
84+ name = Mathdown;
85+ productName = Mathdown;
86+ productReference = 09ED4FD71F6995E200289153 /* Mathdown */;
87+ productType = "com.apple.product-type.tool";
88+ };
89+/* End PBXNativeTarget section */
90+
91+/* Begin PBXProject section */
92+ 09ED4FCF1F6995E200289153 /* Project object */ = {
93+ isa = PBXProject;
94+ attributes = {
95+ LastSwiftUpdateCheck = 0900;
96+ LastUpgradeCheck = 0900;
97+ ORGANIZATIONNAME = "Ilya Kos";
98+ TargetAttributes = {
99+ 09ED4FD61F6995E200289153 = {
100+ CreatedOnToolsVersion = 9.0;
101+ ProvisioningStyle = Automatic;
102+ };
103+ };
104+ };
105+ buildConfigurationList = 09ED4FD21F6995E200289153 /* Build configuration list for PBXProject "Mathdown" */;
106+ compatibilityVersion = "Xcode 8.0";
107+ developmentRegion = en;
108+ hasScannedForEncodings = 0;
109+ knownRegions = (
110+ en,
111+ );
112+ mainGroup = 09ED4FCE1F6995E200289153;
113+ productRefGroup = 09ED4FD81F6995E200289153 /* Products */;
114+ projectDirPath = "";
115+ projectRoot = "";
116+ targets = (
117+ 09ED4FD61F6995E200289153 /* Mathdown */,
118+ );
119+ };
120+/* End PBXProject section */
121+
122+/* Begin PBXSourcesBuildPhase section */
123+ 09ED4FD31F6995E200289153 /* Sources */ = {
124+ isa = PBXSourcesBuildPhase;
125+ buildActionMask = 2147483647;
126+ files = (
127+ 09ED4FDB1F6995E200289153 /* main.swift in Sources */,
128+ );
129+ runOnlyForDeploymentPostprocessing = 0;
130+ };
131+/* End PBXSourcesBuildPhase section */
132+
133+/* Begin XCBuildConfiguration section */
134+ 09ED4FDC1F6995E200289153 /* Debug */ = {
135+ isa = XCBuildConfiguration;
136+ buildSettings = {
137+ ALWAYS_SEARCH_USER_PATHS = NO;
138+ CLANG_ANALYZER_NONNULL = YES;
139+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
140+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
141+ CLANG_CXX_LIBRARY = "libc++";
142+ CLANG_ENABLE_MODULES = YES;
143+ CLANG_ENABLE_OBJC_ARC = YES;
144+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
145+ CLANG_WARN_BOOL_CONVERSION = YES;
146+ CLANG_WARN_COMMA = YES;
147+ CLANG_WARN_CONSTANT_CONVERSION = YES;
148+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
149+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
150+ CLANG_WARN_EMPTY_BODY = YES;
151+ CLANG_WARN_ENUM_CONVERSION = YES;
152+ CLANG_WARN_INFINITE_RECURSION = YES;
153+ CLANG_WARN_INT_CONVERSION = YES;
154+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
155+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
156+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
157+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
158+ CLANG_WARN_STRICT_PROTOTYPES = YES;
159+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
160+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
161+ CLANG_WARN_UNREACHABLE_CODE = YES;
162+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
163+ CODE_SIGN_IDENTITY = "Mac Developer";
164+ COPY_PHASE_STRIP = NO;
165+ DEBUG_INFORMATION_FORMAT = dwarf;
166+ ENABLE_STRICT_OBJC_MSGSEND = YES;
167+ ENABLE_TESTABILITY = YES;
168+ GCC_C_LANGUAGE_STANDARD = gnu11;
169+ GCC_DYNAMIC_NO_PIC = NO;
170+ GCC_NO_COMMON_BLOCKS = YES;
171+ GCC_OPTIMIZATION_LEVEL = 0;
172+ GCC_PREPROCESSOR_DEFINITIONS = (
173+ "DEBUG=1",
174+ "$(inherited)",
175+ );
176+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
177+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
178+ GCC_WARN_UNDECLARED_SELECTOR = YES;
179+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
180+ GCC_WARN_UNUSED_FUNCTION = YES;
181+ GCC_WARN_UNUSED_VARIABLE = YES;
182+ MACOSX_DEPLOYMENT_TARGET = 10.12;
183+ MTL_ENABLE_DEBUG_INFO = YES;
184+ ONLY_ACTIVE_ARCH = YES;
185+ SDKROOT = macosx;
186+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
187+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
188+ };
189+ name = Debug;
190+ };
191+ 09ED4FDD1F6995E200289153 /* Release */ = {
192+ isa = XCBuildConfiguration;
193+ buildSettings = {
194+ ALWAYS_SEARCH_USER_PATHS = NO;
195+ CLANG_ANALYZER_NONNULL = YES;
196+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
197+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
198+ CLANG_CXX_LIBRARY = "libc++";
199+ CLANG_ENABLE_MODULES = YES;
200+ CLANG_ENABLE_OBJC_ARC = YES;
201+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
202+ CLANG_WARN_BOOL_CONVERSION = YES;
203+ CLANG_WARN_COMMA = YES;
204+ CLANG_WARN_CONSTANT_CONVERSION = YES;
205+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
206+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
207+ CLANG_WARN_EMPTY_BODY = YES;
208+ CLANG_WARN_ENUM_CONVERSION = YES;
209+ CLANG_WARN_INFINITE_RECURSION = YES;
210+ CLANG_WARN_INT_CONVERSION = YES;
211+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
212+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
213+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
214+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
215+ CLANG_WARN_STRICT_PROTOTYPES = YES;
216+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
217+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
218+ CLANG_WARN_UNREACHABLE_CODE = YES;
219+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
220+ CODE_SIGN_IDENTITY = "Mac Developer";
221+ COPY_PHASE_STRIP = NO;
222+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
223+ ENABLE_NS_ASSERTIONS = NO;
224+ ENABLE_STRICT_OBJC_MSGSEND = YES;
225+ GCC_C_LANGUAGE_STANDARD = gnu11;
226+ GCC_NO_COMMON_BLOCKS = YES;
227+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
228+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
229+ GCC_WARN_UNDECLARED_SELECTOR = YES;
230+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
231+ GCC_WARN_UNUSED_FUNCTION = YES;
232+ GCC_WARN_UNUSED_VARIABLE = YES;
233+ MACOSX_DEPLOYMENT_TARGET = 10.12;
234+ MTL_ENABLE_DEBUG_INFO = NO;
235+ SDKROOT = macosx;
236+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
237+ };
238+ name = Release;
239+ };
240+ 09ED4FDF1F6995E200289153 /* Debug */ = {
241+ isa = XCBuildConfiguration;
242+ buildSettings = {
243+ CODE_SIGN_STYLE = Automatic;
244+ DEVELOPMENT_TEAM = 8J63JZYYHZ;
245+ PRODUCT_NAME = "$(TARGET_NAME)";
246+ SWIFT_VERSION = 4.0;
247+ };
248+ name = Debug;
249+ };
250+ 09ED4FE01F6995E200289153 /* Release */ = {
251+ isa = XCBuildConfiguration;
252+ buildSettings = {
253+ CODE_SIGN_STYLE = Automatic;
254+ DEVELOPMENT_TEAM = 8J63JZYYHZ;
255+ PRODUCT_NAME = "$(TARGET_NAME)";
256+ SWIFT_VERSION = 4.0;
257+ };
258+ name = Release;
259+ };
260+/* End XCBuildConfiguration section */
261+
262+/* Begin XCConfigurationList section */
263+ 09ED4FD21F6995E200289153 /* Build configuration list for PBXProject "Mathdown" */ = {
264+ isa = XCConfigurationList;
265+ buildConfigurations = (
266+ 09ED4FDC1F6995E200289153 /* Debug */,
267+ 09ED4FDD1F6995E200289153 /* Release */,
268+ );
269+ defaultConfigurationIsVisible = 0;
270+ defaultConfigurationName = Release;
271+ };
272+ 09ED4FDE1F6995E200289153 /* Build configuration list for PBXNativeTarget "Mathdown" */ = {
273+ isa = XCConfigurationList;
274+ buildConfigurations = (
275+ 09ED4FDF1F6995E200289153 /* Debug */,
276+ 09ED4FE01F6995E200289153 /* Release */,
277+ );
278+ defaultConfigurationIsVisible = 0;
279+ defaultConfigurationName = Release;
280+ };
281+/* End XCConfigurationList section */
282+ };
283+ rootObject = 09ED4FCF1F6995E200289153 /* Project object */;
284+}
Mathdown/Mathdown.xcodeproj/project.xcworkspace/contents.xcworkspacedatanew file+7
@@ -0,0 +1,7 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<Workspace
3+ version = "1.0">
4+ <FileRef
5+ location = "self:Mathdown.xcodeproj">
6+ </FileRef>
7+</Workspace>
Mathdown/Mathdown/main.swiftnew file+136
@@ -0,0 +1,136 @@
1+//
2+// main.swift
3+// Mathdown
4+//
5+// Created by Ilya Kos on 9/13/17.
6+// Copyright © 2017 Ilya Kos. All rights reserved.
7+//
8+
9+import Foundation
10+
11+enum BracketStyle {
12+ case square
13+ case round
14+ var opening: Character {
15+ switch self {
16+ case .round:
17+ return "("
18+ case .square:
19+ return "["
20+ }
21+ }
22+ var closing: Character {
23+ switch self {
24+ case .round:
25+ return ")"
26+ case .square:
27+ return "]"
28+ }
29+ }
30+}
31+
32+var style: BracketStyle = .round
33+var outputUrl: URL!
34+var inputUrl: URL! {
35+ didSet {
36+ outputUrl = outputUrl ?? inputUrl.deletingPathExtension().appendingPathExtension("xml")
37+ }
38+}
39+
40+var args = CommandLine.arguments.dropFirst()
41+switch args.count {
42+case 0:
43+ print("You didn't provide an input file")
44+ exit(0)
45+case 1:
46+ inputUrl = URL(fileURLWithPath: args.first!)
47+default:
48+ func processArgs() {
49+ if let arg = args.popFirst() {
50+ switch arg {
51+ case "-i":
52+ if let surl = args.popFirst() {
53+ inputUrl = URL(fileURLWithPath: surl)
54+ }
55+ case "-o":
56+ if let surl = args.popFirst() {
57+ outputUrl = URL(fileURLWithPath: surl)
58+ }
59+ case "-s":
60+ style = .square
61+ case "-r":
62+ style = .round
63+ default:
64+ return
65+ }
66+ processArgs()
67+ }
68+ }
69+ processArgs()
70+}
71+enum ElementStyle: String {
72+ case none = ""
73+ case bold = "bold"
74+ case italic = "italic"
75+ case boldItalic = "bold-italic"
76+}
77+let styleCharecters = CharacterSet.init(charactersIn: "_*")
78+extension String.SubSequence {
79+ var style: ElementStyle {
80+ let num = self.prefix(while: {styleCharecters.contains($0.unicodeScalars.first!)}).count
81+ switch num {
82+ case 0:
83+ return .none
84+ case 1:
85+ return .italic
86+ case 2:
87+ return .bold
88+ default:
89+ return .boldItalic
90+ }
91+ }
92+ func trimmingStyleCharecters() -> String {
93+ return self.trimmingCharacters(in: styleCharecters)
94+ }
95+}
96+func process(mth: String) -> String {
97+ let whitespace = CharacterSet.whitespaces
98+
99+ var out = "<math>"
100+ let lines = mth.split(separator: "\n", omittingEmptySubsequences: false)
101+ .map {$0.trimmingCharacters(in: .whitespaces)}
102+ var insideMatrix = false
103+ for line in lines {
104+ switch line {
105+ case "":
106+ if insideMatrix {
107+ out.append("</mtable><mo>\(style.closing)</mo></mrow>")
108+ insideMatrix = false
109+ }
110+ default:
111+ if !insideMatrix {
112+ out.append("<mrow><mo>\(style.opening)</mo><mtable>")
113+ insideMatrix = true
114+ }
115+ out.append("<mtr>")
116+ for element in line.split(
117+ whereSeparator: {c in whitespace.contains(c.unicodeScalars.first!)}) {
118+ let eStyle = element.style
119+ out.append("<mtd><mn mathvariant=\"\(eStyle.rawValue)\">\(element.trimmingStyleCharecters())</mn></mtd>")
120+ }
121+ out.append("</mtr>")
122+ }
123+ }
124+ if insideMatrix {
125+ out.append("</mtable><mo>\(style.closing)</mo></mrow>")
126+ }
127+ out.append("</math>")
128+ return out
129+}
130+
131+do {
132+ let inp = try String.init(contentsOf: inputUrl)
133+ try process(mth: inp).write(to: outputUrl, atomically: true, encoding: .utf8)
134+} catch {
135+ print("Invalid file")
136+}
README.md+26
@@ -1,2 +1,28 @@
11# Mathdown
22A lightweight syntax for matrices.
3+Outputs [MathML](https://en.wikipedia.org/wiki/MathML) format.
4+
5+## Syntax
6+`1 2 3
7+3 2 8`
8+produces
9+![](images/mat1.png)
10+
11+You can also use [Markdown](https://en.wikipedia.org/wiki/Markdown)-style text emphasis
12+- `_<text>_` or `*<text>*` for _italic_
13+- `__<text>__` or `**<text>**` for __bold__
14+- `___<text>___` or `***<text>***` for ___italic and bold___
15+
16+`***1*** 2 __3__
17+3 _2_ 8`
18+produces
19+![](imgeas/mat2.png)
20+
21+## Usage
22+`mathdown -i input.mth -o output.xml`
23+
24+### Parameters
25+- `-i <file path>` Specifies the input path
26+- `-o <file path>` Specifies the output pathfile
27+- `-s` Uses square brackets
28+- `-r` Uses round brackets
images/mat1.pngnew file

Binary file not shown.

images/mat2.pngnew file

Binary file not shown.