2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Matrix classの行列をtex形式に変換する

Last updated at Posted at 2016-02-26

目的

Matrix classの行列をtex形式に変換したい.
(そうすれば,プログラムを書いて求めた行列をすぐtexファイルにコピペすることができて嬉しい.)

Rubyコード

require "matrix"
class Matrix
	def matex
		a=self.to_a
		column=a[0].length
		print "\\begin{pmatrix}\n"
		a.each do |x|
			x.each.with_index{|element, i|
				print element 
				if (i+1)%column==0 
					print " \\\\\n" 
				else
					print " & "
				end
			}
		end
		print "\\end{pmatrix}\n"
	end
end
Matrix[[1,2],
      [3,4]].matex
#⇒
#\begin{pmatrix}
#1 & 2 \\
#3 & 4 \\
#\end{pmatrix}

参考にしたサイト

http://noy.hatenablog.com/entry/20110829/1314631664

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?