Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created October 31, 2013 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/7254018 to your computer and use it in GitHub Desktop.
Save zr-tex8r/7254018 to your computer and use it in GitHub Desktop.
LaTeX: Doing (or not doing) Python with PythonTeX
% 文字コードは一応UTF-8
\documentclass[a4paper]{jsarticle}
\usepackage{pythontex}
\usepackage{type1cm}
\newcommand*{\textFunny}[1]{%
{\usefont{OT1}{cmfr}{m}{it}\LARGE #1}%
}
\newcommand{\NabeAzz}[1]{%
\pyc{nabeazz(#1)}%
}
\begin{pycode}
def nabeazz(n):
for i in range(1, n + 1):
if i % 3 == 0 or '3' in str(i):
print(r"\textFunny{%d}" % i)
else:
print(i)
\end{pycode}
\begin{document}
3の倍数と3が付く数字のときだけFunnyになります。
\begin{quote}
\NabeAzz{40}
\end{quote}
\end{document}
% 文字コードは一応UTF-8
\documentclass[a4paper]{jsarticle}
\usepackage[usefamily=ruby]{pythontex}
\usepackage{type1cm}
\newcommand*{\textFunny}[1]{%
{\usefont{OT1}{cmfr}{m}{it}\LARGE #1}%
}
\newcommand{\NabeAzz}[1]{%
\rubyc{nabeazz(#1)}%
}
\begin{rubycode}
def nabeazz(n)
1.upto(n).each do |i|
puts((i % 3 == 0 || i.to_s =~ /3/) ? "\\textFunny{#{i}}" : i)
end
end
\end{rubycode}
\begin{document}
3の倍数と3が付く数字のときだけFunnyになります。
\begin{quote}
\NabeAzz{40}
\end{quote}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment