Render Equations and Math Formulas using C#

LaTeX is an exceptional tool for typesetting mathematical content, enabling you to effortlessly embed formulas and equations within a 텍스 file. This source document, crafted with LaTeX, provides a comprehensive range of commands for formatting text, symbols, mathematical expressions, and graphics. In this article, you’ll learn how to efficiently render LaTeX equations and math formulas using C# with the Aspose TeX API, widely recognized as the best C# library for LaTeX rendering.

테이블 콘텐츠

C# API to Render LaTeX 평등 및 수학 수식

To render LaTeX math formulas, we will utilize the .NET을 위한 ASPOSE.TEX API. This robust .NET LaTeX equation rendering library allows you to typeset TeX files into various formats, including PDF, XPS, or images. It is perfect for high-performance LaTeX rendering in C# and is recognized as the best C# library for LaTeX rendering.

You can either DLL 다운로드 of the API or install it via 나그네:

PM> Install-Package Aspose.TeX

Render LaTeX Inline 수학 수식을 사용하여 C#

간단한 인라인 수학 수식이나 평등을 제출하는 것은 간단합니다.이 단계를 따르십시오 :

  • MathRendererOptions 클래스의 예를 만드십시오.
  • LaTeX 문서 사전을 지정합니다.
  • Optionally, adjust properties such as 스케일, TextColor, BackgroundColor, 그리고 등등
  • 수식 이미지에 대한 출력 스트림을 만듭니다.
  • Render() 방법을 호출하여 수식 줄, 흐름, MathRendeerOptions 및 출력 이미지 크기를 논쟁으로 전달합니다.

다음은 코드 샘플을 보여줍니다 C#를 사용하여 수학 공식을 프로그래밍하는 방법 :

// This code example demonstrates how to render math formulas and equations
// Create rendering options specifying the image resolution 150 dpi
MathRendererOptions options = new PngMathRendererOptions() { Resolution = 150 };
// Specify the preamble.
options.Preamble = @"\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}";
// Specify the scaling factor 300%.
options.Scale = 3000;
// Specify the foreground color.
options.TextColor = System.Drawing.Color.Black;
// Specify the background color.
options.BackgroundColor = System.Drawing.Color.White;
// Specify the output stream for the log file.
options.LogStream = new MemoryStream();
// Specify whether to show the terminal output on the console or not.
options.ShowTerminal = true;
// The variable in which the dimensions of the resulting image will be written.
System.Drawing.SizeF size = new System.Drawing.SizeF();
// Create the output stream for the formula image.
using (Stream stream = File.Open(@"D:\Files\Tex\math-formula.png", FileMode.Create))
// Run rendering.
MathRenderer.Render(@"This is a sample formula $f(x) = x^2$ example.", stream, options, out size);
// Show other results.
System.Console.Out.WriteLine(options.ErrorReport);
System.Console.Out.WriteLine();
System.Console.Out.WriteLine("Size: " + size);
Render Inline Math Formulas using C#

Render Inline Math Formulas using C#

렌더 컴플렉스 LaTeX 균형 C# {# 렌더 컴플렉스-균형-CSharp}

복잡한 LaTeX 방정식은 이전과 동일한 단계를 따르지만 단계 #4에서 더 흥미로운 수식 줄을 가지고 있습니다.

MathRenderer.Render(@"\begin{equation*}
                e^x = x^{\color{red}0} + x^{\color{red}1} + 
                \frac{x^{\color{red}2}}{2} + 
                \frac{x^{\color{red}3}}{6} + 
                \cdots = \sum_{n\geq 0} \frac{x^{\color{red}n}}{n!}
                \end{equation*}", stream, options, out size);
Render Complex Equations in C#

Render Complex Equations in C#

C#에서 긴 평등을 표시

여러 라인에 걸쳐 긴 평등을 표시하려면 LaTeX Multline 환경에서 다음과 같은 접근 방식을 사용하십시오.

MathRenderer.Render(@"\begin{document}
                    \begin{multline*}
	            p(x) = x^1+x^2+x^3+x^4\\ 
	            - x^4 - x^3 - x^2 - x
	            \end{multline*}
                    \end{document}", stream, options, out size);
Display Long Equations

Display Long Equations in C#

C#를 사용하여 여러 평등을 조정

당신은 단계 #4에서 수식 줄을 변경하여 여러 방정식을 조정할 수 있습니다 :

MathRenderer.Render(@"\begin{document}
                         \begin{align*}
                         a+b   &  a-b   &  (a+b)(a-b)\\
                         x+y   &  x-y   &  (x+y)(x-y)\\
                         p+q   &  p-q   &  (p+q)(p-q)
                         \end{align*}
                         \end{document}", stream, options, out size);
Align Several Equations using C#

Align Several Equations using C#

C#를 사용하여 그룹 및 센터 평등

여러 평등을 그룹화하고 중심화하려면 다음 코드를 사용하십시오.

MathRenderer.Render(@"\begin{gather*} 
                (a+b)=a^2+b^2+2ab \\ 
                (a-b)=a^2+b^2-2ab \\ 
                (a-b)=a^2+b^2-2ab
                \end{gather*}", stream, options, out size);
Group and Center Equations using C#

Group and Center Equations using C#

Render Matrices, Parentheses, and Brackets in C# {#Render-Matrices,-Parenthesis,-and-Brackets-in-CSharp}

당신은 매트리스, 파렌테세스 및 브래켓을 비슷하게 수행 할 수 있습니다 :

MathRenderer.Render(@"\begin{document}
	            [ 
	            \left \{
	              \begin{tabular}{ccc}
	              1 & 4 & 7 \\
	              2 & 5 & 8 \\
	              3 & 6 & 9 
	              \end{tabular}
	            \right \}
	            ]
	            \end{document}", stream, options, out size);
Render Matrices, Parenthesis, and Brackets in C#

Render Matrices, Parenthesis, and Brackets in C#

C#를 사용하여 Render Fractions and Binomials-using-CSharp}

fractions 및 binomials를 수행하려면,이 구조를 따르십시오 :

MathRenderer.Render(@"\begin{document}
	            [
	                \binom{n}{k} = \frac{n!}{k!(n-k)!}
	            ]
	            \end{document}", stream, options, out size);
Render Fractions and Binomials using C#

Render Fractions and Binomials using C#

무료 라이센스를 얻으십시오

You can 무료 임시 라이센스를 받으십시오. to evaluate the library without limitations.

결론

이 기사에서 우리는 다음과 같은 방법을 조사했습니다 :

  • C#에서 간단하고 복잡한 수학 수식과 방정식을 제공합니다.
  • 일관성과 그룹 방정식은 프로그래밍으로 진행됩니다.
  • 렌더 매트리스, 파렌테세스, 브래켓, 부분 및 binomials.

Beyond rendering LaTeX equations and math formulas in C#, you can delve deeper into the .NET을 위한 ASPOSE.TEX API by referring to the 문서화. If you have any questions, feel free to reach out on our 무료 지원 포럼.

Aspose 플러그인을 사용하면 C#에서 높은 품질의 LaTeX 프레젠테이션을 달성하고 WinForms, WPF 또는 .NET MAUI를 사용하는지 여부를 응용 프로그램에 LaTeX 평등을 통합 할 수 있습니다. C# ASP.NET 응용 프로그램에서 수학 표현을 프레젠테이션하기 시작하십시오.

또한, LaTeX를 수행하는 방법을 이해하는 것은 수학적 콘텐츠로 일하는 개발자에게 필수적입니다. C# LaTEX와 같은 적절한 도구를 사용하면 복잡한 수식을 프로젝트에 쉽게 통합 할 수 있습니다. *LaTex 그룹 방정식에 관심이 있거나 Latex multline를 렌더링해야하는지 여부, 이 가이드는 필요한 지식을 제공해야합니다.

More in this category