Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple latex to pdf using tikz #29

Open
nassuphis opened this issue Jun 13, 2018 · 10 comments
Open

multiple latex to pdf using tikz #29

nassuphis opened this issue Jun 13, 2018 · 10 comments
Labels

Comments

@nassuphis
Copy link
Member

we need to create a large number of icons representing individual pairs/shares
this is best done using a single .Rnw file which creates each icon using the tikz library
and then outputs the reulting icon per pair to the appropriate file name

@nassuphis
Copy link
Member Author

make_external_latex<-function(
  latex="testing123",
  filename=NULL
)paste0(
  if(!is.null(filename)){paste0("\\tikzsetnextfilename{",filename,"}"," ")}else{""},
  "\\tikz{\\path (0,0) node[inner sep=0,outer sep=0]{",
  latex,
  "};}"
)

@nassuphis
Copy link
Member Author

for pair icons, we have a function that paints the icon ofr a pair using tikz

pair_icon<-function(
  pair,
  pair_exposure,
  pair_days,
  pair_pnl,
  pair_long_pnl,
  pair_short_pnl,
  drop_one_pair_pnl,
  local_pnl
){
  icon_items<-c(
    paste0("\\multicolumn{1}{@{}c@{}}{",pair_with_pm_color(pair=pair),"}"),
    paste0("\\multicolumn{1}{@{}c@{}}{",pair_price_action(pair=pair,pair_pnl=pair_pnl,w=21,height=2,width = 30,units="mm"),"}"),
    paste0("\\multicolumn{1}{@{}c@{}}{",pair_technicals(
      pair=pair,
      w=365,
      pair_exposure=pair_exposure,
      pair_days=pair_days,
      pair_long_pnl=pair_long_pnl,
      pair_short_pnl=pair_short_pnl,
      drop_one_pair_pnl=drop_one_pair_pnl,
      local_pnl=local_pnl
    ),"}"),
    pair_leg(pair=pair,pair_exposure=pair_exposure,direction=(1),max_char=12),
    pair_leg(pair=pair,pair_exposure=pair_exposure,direction=(-1),max_char=12)
  )
  tbl(x=icon_items,sep=" \\\\ \n",align="@{}p{3.0cm}@{}")
}

@nassuphis
Copy link
Member Author

and we loop over pair icons like this:

latex_icons<-mapply(pair_icon,pair=pairs,MoreArgs=list(
  pair_exposure=pair_exposure,
  pair_days=pair_days,
  pair_pnl=pair_local_pnl,
  pair_long_pnl=pair_long_pnl,
  pair_short_pnl=pair_short_pnl,
  drop_one_pair_pnl=drop_one_pair_pnl,
  local_pnl=local_pnl
),SIMPLIFY = FALSE)

append2log("create_pair_icons.Rnw : create external latex commands")
external_latex_icons<-mapply(
  function(latex,file){
    make_external_latex(latex=latex,filename=file)
  },
  latex=latex_icons,
  #file=paste0("N:/Depts/Share/UK Alpha Team/Analytics/pair_icons/",pairs),
  file=paste0(pairs),
  SIMPLIFY=TRUE
)

@nassuphis
Copy link
Member Author

and finally, we put the latex generated above into the doc:

\Sexpr{paste(external_latex_icons,collapse="\n")}

@nassuphis
Copy link
Member Author

the output looks like this:

for example, pair ABC1

\tikzsetnextfilename{ABC1} \tikz{\path (0,0) node[inner sep=0,outer sep=0]{\begin{tabular}{@{}p{3.0cm}@{}} \multicolumn{1}{@{}c@{}}{\cellcolor{ABC!33}ABC1} \\ 
\multicolumn{1}{@{}c@{}}{\tikz{
\path 
( 0.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 1.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 3.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 4.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 6.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 7.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 9.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (10.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (12.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (13.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (15.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (16.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (18.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (19.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (21.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (22.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (24.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (25.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (27.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (28.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (30.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
 ;}} \\ 
\multicolumn{1}{@{}c@{}}{\begin{tabular}{@{}l@{\hskip 1pt}l@{\hskip 1pt}l@{}}v0.4 & r3.5 & g164\\{\small\sfrac{RSI}{3m}:56} & {\small\sfrac{RSI}{1m}:55} & {\small\sfrac{RSI}{2w}:53} \\ {\small12m:84} & {\small6m:70} & {\small1m:73} \\ \fbox{\tikz{\fill[green] (8mm,2mm) circle(0.5mm);\fill[red] (0mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.0000mm)--(0.4211mm,0.0469mm)--(0.8421mm,0.1027mm)--(1.2632mm,0.1755mm)--(1.6842mm,0.2334mm)--(2.1053mm,0.3205mm)--(2.5263mm,0.4554mm)--(2.9474mm,0.6254mm)--(3.3684mm,0.8074mm)--(3.7895mm,0.9406mm)--(4.2105mm,1.1091mm)--(4.6316mm,1.2278mm)--(5.0526mm,1.3938mm)--(5.4737mm,1.5400mm)--(5.8947mm,1.6818mm)--(6.3158mm,1.8039mm)--(6.7368mm,1.9513mm)--(7.1579mm,1.9497mm)--(7.5789mm,1.9830mm)--(8.0000mm,2.0000mm);}}&\fbox{\tikz{\fill[green] (5.8947mm,2mm) circle(0.5mm);\fill[red] (0mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.0000mm)--(0.4211mm,0.1384mm)--(0.8421mm,0.3157mm)--(1.2632mm,0.4921mm)--(1.6842mm,0.7207mm)--(2.1053mm,1.0270mm)--(2.5263mm,1.2441mm)--(2.9474mm,1.3247mm)--(3.3684mm,1.4566mm)--(3.7895mm,1.5056mm)--(4.2105mm,1.4962mm)--(4.6316mm,1.5259mm)--(5.0526mm,1.7921mm)--(5.4737mm,1.9330mm)--(5.8947mm,2.0000mm)--(6.3158mm,1.9547mm)--(6.7368mm,1.9089mm)--(7.1579mm,1.7514mm)--(7.5789mm,1.6204mm)--(8.0000mm,1.6426mm);}}&\fbox{\tikz{\fill[green] (7.5789mm,2mm) circle(0.5mm);\fill[red] (3.7895mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,1.1246mm)--(0.4211mm,1.3526mm)--(0.8421mm,1.3573mm)--(1.2632mm,1.2882mm)--(1.6842mm,1.0196mm)--(2.1053mm,0.8503mm)--(2.5263mm,0.6810mm)--(2.9474mm,0.4571mm)--(3.3684mm,0.0453mm)--(3.7895mm,0.0000mm)--(4.2105mm,0.1255mm)--(4.6316mm,0.2511mm)--(5.0526mm,0.5246mm)--(5.4737mm,0.8688mm)--(5.8947mm,1.2140mm)--(6.3158mm,1.5142mm)--(6.7368mm,1.7688mm)--(7.1579mm,1.8961mm)--(7.5789mm,2.0000mm)--(8.0000mm,1.8610mm);}}\\\end{tabular}} \\ 
{\small  DSM } \\ 
{\small  KYG-SX4E }\\ \end{tabular}};}

@nassuphis
Copy link
Member Author

and another one:

\tikzsetnextfilename{ABC11} \tikz{\path (0,0) node[inner sep=0,outer sep=0]{\begin{tabular}{@{}p{3.0cm}@{}} \multicolumn{1}{@{}c@{}}{\cellcolor{ABC!33}ABC11} \\ 
\multicolumn{1}{@{}c@{}}{\tikz{
\path 
( 0.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  ( 1.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  ( 3.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 4.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 6.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  ( 7.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 9.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (10.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (12.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (13.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (15.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (16.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (18.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (19.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (21.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (22.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (24.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (25.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (27.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (28.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (30.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
 ;}} \\ 
\multicolumn{1}{@{}c@{}}{\begin{tabular}{@{}l@{\hskip 1pt}l@{\hskip 1pt}l@{}}v0.2 & r(-13) & g153\\{\small\sfrac{RSI}{3m}:53} & {\small\sfrac{RSI}{1m}:55} & {\small\sfrac{RSI}{2w}:63} \\ {\small12m:98} & {\small6m:96} & {\small1m:93} \\ \fbox{\tikz{\fill[green] (5.4737mm,2mm) circle(0.5mm);\fill[red] (0mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.0000mm)--(0.4211mm,0.1280mm)--(0.8421mm,0.1769mm)--(1.2632mm,0.2794mm)--(1.6842mm,0.3225mm)--(2.1053mm,0.4585mm)--(2.5263mm,0.6763mm)--(2.9474mm,1.0189mm)--(3.3684mm,1.3049mm)--(3.7895mm,1.6096mm)--(4.2105mm,1.9009mm)--(4.6316mm,1.9660mm)--(5.0526mm,1.9892mm)--(5.4737mm,2.0000mm)--(5.8947mm,1.8859mm)--(6.3158mm,1.6279mm)--(6.7368mm,1.4525mm)--(7.1579mm,1.4519mm)--(7.5789mm,1.5111mm)--(8.0000mm,1.7738mm);}}&\fbox{\tikz{\fill[green] (8mm,2mm) circle(0.5mm);\fill[red] (5.4737mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,1.5262mm)--(0.4211mm,1.6209mm)--(0.8421mm,1.5976mm)--(1.2632mm,1.5056mm)--(1.6842mm,1.3864mm)--(2.1053mm,1.1701mm)--(2.5263mm,1.0771mm)--(2.9474mm,1.1686mm)--(3.3684mm,1.2317mm)--(3.7895mm,1.0853mm)--(4.2105mm,0.8643mm)--(4.6316mm,0.6393mm)--(5.0526mm,0.2525mm)--(5.4737mm,0.0000mm)--(5.8947mm,0.0069mm)--(6.3158mm,0.3880mm)--(6.7368mm,0.7776mm)--(7.1579mm,1.1803mm)--(7.5789mm,1.6686mm)--(8.0000mm,2.0000mm);}}&\fbox{\tikz{\fill[green] (5.8947mm,2mm) circle(0.5mm);\fill[red] (2.5263mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.6608mm)--(0.4211mm,0.6367mm)--(0.8421mm,0.5624mm)--(1.2632mm,0.2812mm)--(1.6842mm,0.1040mm)--(2.1053mm,0.0520mm)--(2.5263mm,0.0000mm)--(2.9474mm,0.1133mm)--(3.3684mm,0.5519mm)--(3.7895mm,0.8398mm)--(4.2105mm,1.0640mm)--(4.6316mm,1.2882mm)--(5.0526mm,1.6259mm)--(5.4737mm,1.8365mm)--(5.8947mm,2.0000mm)--(6.3158mm,1.9240mm)--(6.7368mm,1.6468mm)--(7.1579mm,1.5082mm)--(7.5789mm,1.4220mm)--(8.0000mm,1.3894mm);}}\\\end{tabular}} \\ 
{\small  LINU } \\ 
{\small  AI-DAX }\\ \end{tabular}};}

@nassuphis
Copy link
Member Author

image

@nassuphis
Copy link
Member Author

the ionkey file
ICONKEY.pdf

@nassuphis
Copy link
Member Author

amd the "create pair icons" file:
create_pair_icons.pdf

@nassuphis
Copy link
Member Author

images.csv contains a mapping of pair names to the appropriate file:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant