Guest User

Untitled

a guest
Dec 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "data": {
  10. "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFcAAAAOBAMAAACoZ51gAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAiXaZRCLdEO9Uu81m\nqzIdlvb2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABbElEQVQoFXWSv0tCURiGHxM7pmmmQ9EvI2kM\nDBoMh+7ekBC0NzREQ3dqaWhJIoK4f0BgEFQEQVBbBNeWGgyDlqLF/gKLogIJ+z6zkshv+s73Pvc9\n7znnwr8VzZd0boZiFsGL8Dh4hgb+JSHomDmVvHCHv1qNYE5IN4EvoVelLVgm2D8MgSQHTeBDyNmi\n9cASIYWmMk1Q+BDVUWSPvi94v85GE9afr8yzcIMyDFXzDqFCokTloUbNWCZr1Kb3VOtYOt8TlBUm\nXrEJ2L4XU3GZl/Us7LRowN/yiXM5Iuu2scVVHe+aKqRsvG+Q9vyC2v3EuKLlXX0mMq9QtPBvQ3eX\nIg0lB8xpsjXZwbmXNNaCwC4rsl1chXrmM23lSoviaB7ljO6GONu3NecOV5wVaKzvR8nKa2SSsEDZ\nJiUvek17PNxISt/qmE1Wjpi0OWea9iyhiFkXobPgeqN/YBMdKdF6TfhGfiTf6I1EivWX+AQuKl3N\ncVOyJAAAAABJRU5ErkJggg==\n",
  11. "text/latex": [
  12. "$$\\alpha = 0.856$$"
  13. ],
  14. "text/plain": [
  15. "α = 0.856"
  16. ]
  17. },
  18. "execution_count": 1,
  19. "metadata": {},
  20. "output_type": "execute_result"
  21. }
  22. ],
  23. "source": [
  24. "import sympy as sp\n",
  25. "sp.init_printing()\n",
  26. "alpha = sp.symbols('alpha')\n",
  27. "eq = sp.Eq(alpha, 0.856)\n",
  28. "eq"
  29. ]
  30. },
  31. {
  32. "cell_type": "code",
  33. "execution_count": 2,
  34. "metadata": {},
  35. "outputs": [
  36. {
  37. "name": "stdout",
  38. "output_type": "stream",
  39. "text": [
  40. "\\alpha = 0.856\n"
  41. ]
  42. }
  43. ],
  44. "source": [
  45. "print(sp.latex(eq))"
  46. ]
  47. },
  48. {
  49. "cell_type": "markdown",
  50. "metadata": {},
  51. "source": [
  52. "Note that you can't just do the following, as it returns two \\ backslashes due to the need to escape one of them:"
  53. ]
  54. },
  55. {
  56. "cell_type": "code",
  57. "execution_count": 3,
  58. "metadata": {},
  59. "outputs": [
  60. {
  61. "data": {
  62. "text/plain": [
  63. "'\\\\alpha = 0.856'"
  64. ]
  65. },
  66. "execution_count": 3,
  67. "metadata": {},
  68. "output_type": "execute_result"
  69. }
  70. ],
  71. "source": [
  72. "sp.latex(eq)"
  73. ]
  74. },
  75. {
  76. "cell_type": "markdown",
  77. "metadata": {},
  78. "source": [
  79. "You could, however, output them into a file:"
  80. ]
  81. },
  82. {
  83. "cell_type": "code",
  84. "execution_count": 4,
  85. "metadata": {},
  86. "outputs": [
  87. {
  88. "name": "stdout",
  89. "output_type": "stream",
  90. "text": [
  91. "\\alpha = 0.856\n"
  92. ]
  93. }
  94. ],
  95. "source": [
  96. "with open(\"equations.tex\", \"w\") as f:\n",
  97. " f.write(sp.latex(eq))\n",
  98. "with open(\"equations.tex\", \"r\") as f:\n",
  99. " print(f.read()) "
  100. ]
  101. },
  102. {
  103. "cell_type": "code",
  104. "execution_count": 5,
  105. "metadata": {},
  106. "outputs": [
  107. {
  108. "name": "stdout",
  109. "output_type": "stream",
  110. "text": [
  111. "\\alpha = 0.856"
  112. ]
  113. }
  114. ],
  115. "source": [
  116. "cat equations.tex"
  117. ]
  118. },
  119. {
  120. "cell_type": "markdown",
  121. "metadata": {},
  122. "source": [
  123. "I just stumbled upon these options and they're pretty cool:"
  124. ]
  125. },
  126. {
  127. "cell_type": "code",
  128. "execution_count": 6,
  129. "metadata": {},
  130. "outputs": [
  131. {
  132. "name": "stdout",
  133. "output_type": "stream",
  134. "text": [
  135. "$\\alpha = 0.856$\n",
  136. "\\begin{equation}\\alpha = 0.856\\end{equation}\n",
  137. "\\begin{equation*}\\alpha = 0.856\\end{equation*}\n"
  138. ]
  139. }
  140. ],
  141. "source": [
  142. "print(sp.latex(eq, mode='inline'))\n",
  143. "print(sp.latex(eq, mode='equation'))\n",
  144. "print(sp.latex(eq, mode='equation*'))"
  145. ]
  146. },
  147. {
  148. "cell_type": "code",
  149. "execution_count": 7,
  150. "metadata": {},
  151. "outputs": [
  152. {
  153. "name": "stdout",
  154. "output_type": "stream",
  155. "text": [
  156. "alpha_i = 0.856\n"
  157. ]
  158. }
  159. ],
  160. "source": [
  161. "print(sp.latex(eq, symbol_names={alpha: \"alpha_i\"}))"
  162. ]
  163. }
  164. ],
  165. "metadata": {
  166. "kernelspec": {
  167. "display_name": "Python [conda env:3point6]",
  168. "language": "python",
  169. "name": "conda-env-3point6-py"
  170. },
  171. "language_info": {
  172. "codemirror_mode": {
  173. "name": "ipython",
  174. "version": 3
  175. },
  176. "file_extension": ".py",
  177. "mimetype": "text/x-python",
  178. "name": "python",
  179. "nbconvert_exporter": "python",
  180. "pygments_lexer": "ipython3",
  181. "version": "3.6.2"
  182. }
  183. },
  184. "nbformat": 4,
  185. "nbformat_minor": 2
  186. }
Add Comment
Please, Sign In to add comment