C#에서 LaTeX를 PNG로 렌더링하는 방법

이 단계별 방법 가이드에서는 C#에서 LaTeX을(를) PNG로 렌더링하는 방법을 배웁니다. 이 자습서의 코드 조각을 사용하면 몇 단계만 거치면 C#에서 라텍스를 png로 쉽게 렌더링할 수 있습니다.

C#에서 LaTeX를 PNG로 렌더링하는 단계

  1. NuGet.org에서 Aspose.TeX for .NET 패키지 설치
  2. Aspose.TeX, Aspose.TeX.IOAspose.TeX.Presentation.Image 네임스페이스 포함
  3. SetLicense 메서드를 사용하여 .NET용 Aspose.TeX에 라이선스 적용
  4. TeXConfig 설정으로 TeXOptions 객체 생성
  5. 파일을 읽고 저장할 입력 및 출력 작업 디렉토리 설정
  6. TerminalOutput 옵션을 OutputFileTerminal로 설정
  7. PngSaveOptions 개체 생성 및 속성 설정
  8. Typeset 메소드에 전달할 ImageDevice 객체 생성
  9. 조판 방법을 사용하여 조판 작업 실행

위의 단계는 C#에서 TeX를 PNG로 쉽게 변환하는 데 도움이 됩니다. 입력 TeX file은 옵션에 지정된 작업 디렉토리에서 읽고 출력 PNG 파일은 출력 작업 디렉토리에 배치됩니다.

C#에서 LaTeX를 PNG로 렌더링하는 코드

using System;
using System.IO;
//Add reference to Aspose.TeX for .NET API
//Use following namespaces to render Latex file to PNG format
using Aspose.TeX;
using Aspose.TeX.IO;
using Aspose.TeX.Presentation.Image;
namespace RenderLatexToPNG
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before rendering latex file to PNG format
Aspose.TeX.License AsposeTeXLicense = new Aspose.TeX.License();
AsposeTeXLicense.SetLicense(@"c:\asposelicense\license.lic");
//Create TeXOptions object with ObjectTex config settings
TeXOptions TeXFormatOptions = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
//Set input and output working directory
TeXFormatOptions.InputWorkingDirectory = new InputFileSystemDirectory(@"c:\samples");
TeXFormatOptions.OutputWorkingDirectory = new OutputFileSystemDirectory(@"c:\samples");
//Set output terminal option to file terminal to save to a file
TeXFormatOptions.TerminalOut = new OutputFileTerminal(TeXFormatOptions.OutputWorkingDirectory);
//PNG save options
PngSaveOptions pngSaveOptions = new PngSaveOptions();
pngSaveOptions.Resolution = 300;
TeXFormatOptions.SaveOptions = pngSaveOptions;
//Create an ImageDevice object
ImageDevice imageDevice = new ImageDevice();
//Run typesetting.
TeX.Typeset("customtex", imageDevice, TeXFormatOptions);
}
}
}

위에 표시된 코드 조각은 몇 단계로 C#에서 TeX를 PNG로 렌더링하는 방법을 명확하게 보여줍니다. 출력을 파일 시스템에 저장하므로 콘솔 출력 터미널 대신 파일 터미널을 출력 터미널로 지정했습니다.

이 튜토리얼을 사용하여 C# 및 .NET 애플리케이션용 LaTeX 렌더러를 쉽게 구축할 수 있습니다.

 한국인